Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
I am trying to write a DAX measure expression to summarize a fact table value based on complex conditions in related dimension tables. The SQL I am trying to emulate looks like this:
SELECT SUM(WOF.EstimatedHours)/100 FROM WorkOrdersFact WO inner join DimWorkOrderOverrides WOR on WO.DimWorkOrderOverridesID = WOR.DimWorkOrderOverridesID inner join DimWorkOrderDocType WDT on WO.DimWorkOrderDocTypeID = WDT.DimWorkOrderDocTypeID WHERE (WOR.Description2 IN ('307','308','302','311','390')) OR WDT.WorkOrderDocType = 'SV' and WO.WorkOrderType = 'X'
The following code represents the best I could come up with but it seems to me that there must be a better way. I am applying the OR conditions by creating two separate CALCULATE functions then adding the results before dividing by 100.
(
CALCULATE(SUM('Work Orders'[Estimated Hours]),
FILTER('Work Order Doc Type', 'Work Order Doc Type'[Work Order Doc Type] = "SV"),
FILTER('Work Orders', 'Work Orders'[Work Order Type] = "X"))
+
CALCULATE(SUM('Work Orders'[Estimated Hours]),
FILTER('Work Order Overrides', 'Work Order Overrides'[Work Order GL Description2] in {"307","308","302","311","390"}))
)
/100
note that the "IN" operator is now allowed but is not recognized by intellisense. Also note that the referenced tables are already joined in the PBI Relationships view.
Please give me your ideas on the optimal way to accomplish this.
Solved! Go to Solution.
Edit. Sorry, I just realise the or logic won't work So I deleted my suggestion. I think yours is pretty good
I have been search for ages to find the correct syntax to apply a dimension table filter to a fact table value during measure calculation...this just saved my weekend!!! Love this community
Edit. Sorry, I just realise the or logic won't work So I deleted my suggestion. I think yours is pretty good
Hi @Anonymous,
Your DAX is good. The filter "WHERE (WOR.Description2 IN ('307','308','302','311','390'))" is for special values, so I am unable to formut it more intelligently after research. We must enumerate the values one by one.
Best Regards,
Angelia
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
94 | |
86 | |
82 | |
70 | |
49 |
User | Count |
---|---|
143 | |
123 | |
107 | |
61 | |
55 |