Forum Discussion
Sum dollar value by open orders
I need help with some DAX. I have a working DAX that counts open orders. I am wanting to adjust this DAX to calculate total sales for open orders. I am not sure why it won't calculate. Here is the working version:
Reading the code, it looks like you are picking the date and wanting to sum the 'OB Raw Order Data'[ACT_MATERIAL_COST] where the 'OB Raw Order Data'[CREATE_DATE] is on or before the date and the 'OB Raw Order Data'[Order Closed Date] is > the 'tbl_Calendar'[End Of Month] or it is blank.
Give this measure a try and see if it is what you are looking for.
OB USB = VAR _Date = MIN ( 'tbl_Calendar'[Date] ) VAR _EoM = MIN ( 'tbl_Calendar'[End Of Month] ) RETURN CALCULATE ( SUM ( 'OB Raw Order Data'[ACT_MATERIAL_COST] ), 'OB Raw Order Data'[CREATE_DATE] <= _Date, ( 'OB Raw Order Data'[Order Closed Date] > _EoM || ISBLANK ( 'OB Raw Order Data'[Order Closed Date] ) ) )
9 Replies
- jdbuchanan71Super User
Reading the code, it looks like you are picking the date and wanting to sum the 'OB Raw Order Data'[ACT_MATERIAL_COST] where the 'OB Raw Order Data'[CREATE_DATE] is on or before the date and the 'OB Raw Order Data'[Order Closed Date] is > the 'tbl_Calendar'[End Of Month] or it is blank.
Give this measure a try and see if it is what you are looking for.
OB USB = VAR _Date = MIN ( 'tbl_Calendar'[Date] ) VAR _EoM = MIN ( 'tbl_Calendar'[End Of Month] ) RETURN CALCULATE ( SUM ( 'OB Raw Order Data'[ACT_MATERIAL_COST] ), 'OB Raw Order Data'[CREATE_DATE] <= _Date, ( 'OB Raw Order Data'[Order Closed Date] > _EoM || ISBLANK ( 'OB Raw Order Data'[Order Closed Date] ) ) )- bstark1287Helper II
- jdbuchanan71Super User
Try it with a SUMX over the tmpTable3
OB USD = VAR tmpdollars = ADDCOLUMNS ( 'OB Raw Order Data', "Effective Date", IF ( ISBLANK ( [Order Closed Date] ), TODAY (), [Order Closed Date] ) ) VAR tmpTable2 = SELECTCOLUMNS ( FILTER ( GENERATE ( tmpdollars, 'tbl_Calendar' ), AND ( ( [Date] >= [CREATE_DATE] ) && ( [Date] <= [Effective Date] ), OR ( ( [Order Closed Date] >= [End Of Month] ), ISBLANK ( [Order Closed Date] ) ) ) ), "ID", [ACT_MATERIAL_COST], "Date", [Date] ) VAR tmpTable3 = GROUPBY ( tmpTable2, [ID], "@Sum", SUMX ( CURRENTGROUP (), [Date] ) ) RETURN SUMX ( tmpTable3, [@Sum] )- bstark1287Helper II
It is formatting it as a date now. Not sure why, the working DAX for open tickets formatted it as a whole number. jdbuchanan71
- jdbuchanan71Super User
Change the formatting of the measure.
- bstark1287Helper II
Maybe I am missing something but it will not allow me to change the format
- jdbuchanan71Super User
Oh, you are telling it to look at the [Date] field in the earlier step.
- jdbuchanan71Super User
You need to change the field from [Date] to the whatever the field is that has the amounts you are trying to add up.
- bstark1287Helper II
jdbuchanan71 Thank you, that is getting me one step closer! I have made these changes, but it seems my SUMX either in my Var or in my Return are causing the totals to calculate incorrectly. Any thoughts on how to fix?
OB USB =VAR tmpdollars = ADDCOLUMNS('OB Raw Order Data',"Effective Date",IF(ISBLANK([Order Closed Date]),TODAY(),[Order Closed Date]))VAR tmpTable2 =SELECTCOLUMNS(FILTER(GENERATE(tmpdollars,'tbl_Calendar'),AND(([Date] >= [CREATE_DATE]) && ([Date] <= [Effective Date]),OR(([Order Closed Date] >= [End Of Month]), ISBLANK([Order Closed Date])))),"ID",[Order/Line],"Date",[Date],"Mtl",[ACT_MATERIAL_COST])VAR tmpTable3 = GROUPBY(tmpTable2,[ID],"@Sum",SUMX(CURRENTGROUP(),[Mtl]))RETURN SUMX(tmpTable3,[@Sum])