The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Based on the data below id like to create a measure to calulate the sum of the coumn 'Quantity' with multiple conditions.
Data Example
For example, I'd like to know the total of column quantity for the orders with ordertype "0" and orderstatus "on hold" and "open":
I already tried the following:
Total ongoing Ordertype 0 = CALCULATE(SUM(Order Table[Quantity]),
FILTER(Order Table, Order Table[Ordertype]= "0"),
FILTER(Order Table, Order Table[Order Status]= "Open"),
FILTER(Order Table, Order Table[Order Status]= "On Hold")
)
Expected value would be 4 but somehow this doesnt show up.
What am I doing wrong here? Any suggestions?
PS:
Ordertype (=column type "Whole Number")
Order status (=column type "Text")
Quantity (=column type "Decimal Number")
Solved! Go to Solution.
Hi @fbron
If Ordertype (=column type "Whole Number") you ned to compare to a number, not to text
You are doing a logical AND for Open and On hold for Order status. That would mean you want it to be Open and On hold at the same time. You need an OR instead:
Total ongoing Ordertype 0 =
CALCULATE (
SUM ( 'Order Table'[Quantity] ),
'Order Table'[Ordertype] = 0,
'Order Table'[Order Status] = "Open" || 'Order Table'[Order Status] = "On Hold"
)
or alternatively
Total ongoing Ordertype 0 =
CALCULATE (
SUM ( 'Order Table'[Quantity] ),
'Order Table'[Ordertype] = 0,
'Order Table'[Order Status] IN {"Open", "On Hold"}
)
Please mark the question solved when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
Hi, @fbron , why bother to hardcode those filtering conditions in a measure? Slicers with a simple measure do the trick with ease and with more flexibilities. Dax is born for such a scenario. An Excel file is attached for your reference.
Total Qty = SUM(Order Table[Quantity])
Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension! |
DAX is simple, but NOT EASY! |
Hi @fbron
If Ordertype (=column type "Whole Number") you ned to compare to a number, not to text
You are doing a logical AND for Open and On hold for Order status. That would mean you want it to be Open and On hold at the same time. You need an OR instead:
Total ongoing Ordertype 0 =
CALCULATE (
SUM ( 'Order Table'[Quantity] ),
'Order Table'[Ordertype] = 0,
'Order Table'[Order Status] = "Open" || 'Order Table'[Order Status] = "On Hold"
)
or alternatively
Total ongoing Ordertype 0 =
CALCULATE (
SUM ( 'Order Table'[Quantity] ),
'Order Table'[Ordertype] = 0,
'Order Table'[Order Status] IN {"Open", "On Hold"}
)
Please mark the question solved when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers