Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Rolling Count and Sum for Order Balance

Hello All,

 

Below is the table. Task Completed date is the slicer. I am trying to calculate count of distinct orders and Orders in balance

 

Count of distinct orders = Calculate(distinctcount(Order No))

 

Order Sum = Calculate(SUM(Order Count),ALLEXCEPT(table, Order no),Filter(table, Task completed date = SELECTEDVALUE(Date[Date]))) -- When default date slicer is selected for Order Sum it's displaying null instead of 1

 

Count of distinct orders in balance = Calculate(distinctcount(Order No),Filter(Order Sum = 0))

 

For a instance, if I selected order no 100 and task completed date in the range 4/3/20 to 4/7/2020 then it should display following 

Count of distinct Orders =1

Count of distinct Orders in balance = 0

Order Sum = -100

For another instance, if I selected order no 100 and task completed date in the range 4/7/20 to 4/7/2020 then it should display following 

Count of distinct Orders =1

Count of distinct Orders in balance = 1

Order Sum = 0

 

Please help!!

 

Order NoOrder Completed DateTask Order NoTask Completed DateOrder Count
1004/8/20100-14/7/200
1004/8/20100-14/7/200
1004/8/20100-14/7/200
1004/8/20100-44/3/200
1004/8/20100-44/3/20-100
2003/8/20200-13/7/200
2003/8/20200-23/7/2010
2003/8/20200-33/7/205
2003/8/20200-43/8/20-15
2003/8/20200-43/8/2015
2003/8/20200-43/8/20-15
2003/8/20200-43/8/200
  • Hi Anonymous ,

     

    Try to modify your [Order Sum] measure like so:

    Order Sum =
    CALCULATE (
        SUM ( 'Table'[Order Count] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[Order No] ),
            'Table'[Task Completed Date] IN VALUES ( 'Date'[Date] )
        )
    )
    

     

     

    BTW, .pbix file attached.

     

     

    Best Regards,

    Icey

     

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

3 Replies

  • Anonymous , you should join it task completed date with the date of date table. In case you have more than one date to join use userelation for inactive joins

     

    Order Sum = Calculate(SUM(Table[Order Count]),ALLEXCEPT(table, Table[Order no]))

    Order Sum = Calculate(SUM(Table[Order Count]))

     

    Check how to deal with more than one date and date dimension join

    https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-trend/ba-p/882970

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Amit,

       

      Thanks for the response but I tried that method and it's not working as expected. It was displaying blank for order sum.

       

      Thanks

  • Icey's avatar
    Icey
    Community Support

    Hi Anonymous ,

     

    Try to modify your [Order Sum] measure like so:

    Order Sum =
    CALCULATE (
        SUM ( 'Table'[Order Count] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[Order No] ),
            'Table'[Task Completed Date] IN VALUES ( 'Date'[Date] )
        )
    )
    

     

     

    BTW, .pbix file attached.

     

     

    Best Regards,

    Icey

     

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