Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
bstark1287
Helper II
Helper II

DAX Fix from groupby to a SUM

I have the below DAX which returns the count of [Order/line] if the order is open during a time period. (shows total open orders for each month in history based on [CREATE_DATE] and [Order Closed Date1]).  I need to adjust the DAX to SUM the calculated column [Order_Qty_adj]. I was hoping I could just adjust [ID] to [Order_Qty_adj] and tmpTable1 to SUMX on [ID].  

 

Open Tickets =
VAR tmpTickets = ADDCOLUMNS('OB Raw Order Data1',"Effective Date",IF(ISBLANK([Order Closed Date1]),TODAY(),[Order Closed Date1]))
VAR tmpTable =
SELECTCOLUMNS(
    FILTER(
        GENERATE(
            tmpTickets,
        'tbl_Calendar'
        ),
        AND(      
            ([Date] >= [CREATE_DATE]) && ([Date] <= [Effective Date]),
            OR(([Order Closed Date1] > [End Of Month]), ISBLANK([Order Closed Date1]))
        )
    ),
    "ID",[Order/Line],
    "Date",[Date]
)
VAR tmpTable1 = GROUPBY(tmpTable,[ID],"Count",COUNTX(CURRENTGROUP(),[Date]))
RETURN COUNTROWS(tmpTable1)
1 ACCEPTED SOLUTION
bstark1287
Helper II
Helper II

I ended up deleting the measure entirely and starting from scratch. Because the Order_Qty_adj is a calculated column this was the route I believe best suited. 

 

OB QTY =
VAR _Date = MIN ( 'tbl_Calendar'[End Of Month] )
VAR _EoM = MIN ( 'tbl_Calendar'[End Of Month] )
RETURN
    CALCULATE (
        SUM ( 'OB Raw Order Data1'[Order_Qty_adj]),
        'OB Raw Order Data1'[CREATE_DATE] <= _Date,
        ( 'OB Raw Order Data1'[Order Closed Date1] > _EoM || ISBLANK ( 'OB Raw Order Data1'[Order Closed Date1] ) )
    )

View solution in original post

2 REPLIES 2
bstark1287
Helper II
Helper II

I ended up deleting the measure entirely and starting from scratch. Because the Order_Qty_adj is a calculated column this was the route I believe best suited. 

 

OB QTY =
VAR _Date = MIN ( 'tbl_Calendar'[End Of Month] )
VAR _EoM = MIN ( 'tbl_Calendar'[End Of Month] )
RETURN
    CALCULATE (
        SUM ( 'OB Raw Order Data1'[Order_Qty_adj]),
        'OB Raw Order Data1'[CREATE_DATE] <= _Date,
        ( 'OB Raw Order Data1'[Order Closed Date1] > _EoM || ISBLANK ( 'OB Raw Order Data1'[Order Closed Date1] ) )
    )
v-xinruzhu-msft
Community Support
Community Support

Hi @bstark1287 ,

Maybe you can try the following code:

VAR tmpTable1 = GROUPBY(tmpTable,[ID],"Count",SUMX(CURRENTGROUP(),SUM([Order_Qty_adj])))

You can refer to the following link:

Power BI Group By | How to Use GROUPBY DAX Function in Power BI? (wallstreetmojo.com)

If the information above cannot meet your requirement, can you offer some data example or picture?

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

AugPowerBI_Carousel

Power BI Monthly Update - August 2024

Check out the August 2024 Power BI update to learn about new features.

August Carousel

Fabric Community Update - August 2024

Find out what's new and trending in the Fabric Community.