Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Dax Running Totals Help

Hello,

 

I am fairly new to DAX..

 

I have the table below...

It is basically a table of Company statuses. It has a start date when the status was set, and a end date when a status was changed. Once changed a new row gets entered with the new status.

 

I want to be able to get a running total of by day split by status, but when their is an end subtract from the old status, and add to the new status. It's been driving me up the wall. Anyone got any ideas?

  • Hi Anonymous ,

     

    Please create a Calendar table.

     

    Calendar = 
    CALENDAR ( DATE ( 2022, 1, 1 ), DATE ( 2022, 12, 31 ) )

     

    Then create measure.

     

    CountCompany = 
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[CompanyName] ),
        FILTER (
            'Table',
            'Table'[Start_Date] <= MAX ( 'Calendar'[Date] )
                && (
                    'Table'[END_DATE] >= MAX ( 'Calendar'[Date] )
                        || 'Table'[END_DATE] = BLANK ()
                )
        )
    )

     

    If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
    Best Regards,
    Winniz
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

4 Replies

  • tamerj1's avatar
    tamerj1
    Icon for Community Champion rankCommunity Champion

    Hi Anonymous 

    can you provide some sample data?

  • v-kkf-msft's avatar
    v-kkf-msft
    Icon for Community Support rankCommunity Support

    Hi Anonymous ,

     

    Please create a Calendar table.

     

    Calendar = 
    CALENDAR ( DATE ( 2022, 1, 1 ), DATE ( 2022, 12, 31 ) )

     

    Then create measure.

     

    CountCompany = 
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[CompanyName] ),
        FILTER (
            'Table',
            'Table'[Start_Date] <= MAX ( 'Calendar'[Date] )
                && (
                    'Table'[END_DATE] >= MAX ( 'Calendar'[Date] )
                        || 'Table'[END_DATE] = BLANK ()
                )
        )
    )

     

    If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
    Best Regards,
    Winniz
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hello, 

       

      Yes i used parts of your Measure, and it worked as intended. 

       

      Thank you for the help. 

       

      Thanks

       

      Chris