Prompt
SUMX (
Sales,
Sales[Quantity] * RELATED ( Products[UnitPrice] )
)
Answer
Unit Test Cases for SUMX Function in DAX
Test 1: Verify basic functionality
- Input: Empty Sales table
- Expected Output: 0
EVALUATE
{
"Test 1", SUMX(Sales, Sales[Quantity] * RELATED(Products[UnitPrice]))
}
Test 2: Validate multiplication with positive values
- Input: Sales table with Quantity = 5, UnitPrice = 10
- Expected Output: 50
EVALUATE
{
"Test 2", SUMX(VALUES(Sales), Sales[Quantity] * RELATED(Products[UnitPrice]))
}
Test 3: Evaluate when Quantity is negative
- Input: Sales table with Quantity = -3, UnitPrice = 15
- Expected Output: -45
EVALUATE
{
"Test 3", SUMX(VALUES(Sales), Sales[Quantity] * RELATED(Products[UnitPrice]))
}
Test 4: Check behavior with zero Quantity
- Input: Sales table with Quantity = 0, UnitPrice = 20
- Expected Output: 0
EVALUATE
{
"Test 4", SUMX(VALUES(Sales), Sales[Quantity] * RELATED(Products[UnitPrice]))
}
Test 5: Ensure correct calculation with multiple products
- Input: Sales table with multiple products and quantities
- Expected Output: Sum of (Quantity * UnitPrice) for all products
EVALUATE
{
"Test 5", SUMX(VALUES(Sales), Sales[Quantity] * RELATED(Products[UnitPrice]))
}
Test 6: Validate behavior with null values
- Input: Sales table with Null values
- Expected Output: Null
EVALUATE
{
"Test 6", SUMX(Sales, Sales[Quantity] * RELATED(Products[UnitPrice]))
}
Description
These test cases evaluate the SUMX function in DAX by checking basic functionality, multiplication scenarios, negative values, zero Quantity, multiple products, and null values to ensure accurate calculations and handling of different input scenarios.
More Unit Test Writers
Apache Flink Unit Test WriterApache Pig Unit Test WriterAzure Data Factory Unit Test WriterC/C++ Unit Test WriterCouchDB Unit Test WriterDAX Unit Test WriterExcel Unit Test WriterFirebase Unit Test WriterGoogle BigQuery Unit Test WriterGoogle Sheets Unit Test WriterGraphQL Unit Test WriterHive Unit Test WriterJava Unit Test WriterJavaScript Unit Test WriterJulia Unit Test WriterLua Unit Test WriterM (Power Query) Unit Test WriterMATLAB Unit Test WriterMongoDB Unit Test WriterOracle Unit Test WriterPostgreSQL Unit Test WriterPower BI Unit Test WriterPython Unit Test WriterR Unit Test WriterRedis Unit Test WriterRegex Unit Test WriterRuby Unit Test WriterSAS Unit Test WriterScala Unit Test WriterShell Unit Test WriterSPSS Unit Test WriterSQL Unit Test WriterSQLite Unit Test WriterStata Unit Test WriterTableau Unit Test WriterVBA Unit Test Writer