Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago

Need Help with Cumulative difference based on item#

Hi,

 

I am reaching out to this group for help in calculating cumulative difference of quantity for an item. and the calculation for first instance of the item will be base calculation where as the other instances of the same item follow the base calc differnce from the total quantity. My example here would explain better than my words. any help on this is highly appreciated !! 

Thanks!

 

DescriptionItem #Month YearTotal FqtyRequired ( same as Total Fqty)Curr Released Inv Qty (Base qty)Curr Quarantine Inv Qty (Base Qty)Open QtyQty Remaining (**bleep** Diff)Calc logic required
XXXXItem0001Apr-202011150014Only for the first row for the item - the calculation is  Required - (Curr Released Inv Qty + Curr Qurantine Inv Qty + Open Qty)
XXXXItem0001May-20209915005Above value + (Open Qty - Required)
XXXXItem0001Jun-202013131500-8Above value + (Open Qty - Required)
YYYYItem0002Apr-20202223900237follow the first value calculation for first instance of the item
Only for the first row for the item - the calculation is  Required - (Curr Released Inv Qty + Curr Qurantine Inv Qty + Open Qty)
YYYYItem0002May-2020181823900219Above value + (Open Qty - Required)
YYYYItem0002Jun-2020262623900193Above value + (Open Qty - Required)

11 Replies

  • Anonymous , not very clear what you mean by the above value. The logic does not fit in

    We can create a measure like

    Cumm balance= CALCULATE(SUM(Table[Released]),filter(date,date[date] <=max(Table[Date])))

    - CALCULATE(SUM(Table[Required]),filter(date,date[date] <=max(Table[Date])))

     

    To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
    https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
    https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
    https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

    See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-YTD-LYTD-Week-Over-Week/m-p/1051626#M184


    Appreciate your Kudos.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks Amit for the reply, Above here refers to the previous value of the item's reamin Qty.

       

      XXXXItem0001Apr-202011150014
      XXXXItem0001May-2020991500(14- (0+9)) (Previous value + (Open Qty - Required Qty))
  • negi007's avatar
    negi007
    Community Champion

    AnonymousYour calculation seems to be little complicated to achieve but not impossible. I request you to share your excel file with the calculation, will then suggest appropriate solution to you. Thanks

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks for the reply, i am unable to attach my PBI file or Excel file in this post. How can i do that?

      • negi007's avatar
        negi007
        Community Champion

        AnonymousYou could use google drive or one drive to attached powerbi file. Else you can share your excel file with formula calculation that would also help

  • v-alq-msft's avatar
    v-alq-msft
    Community Support

    Hi, Anonymous 

     

    You may create a calculated column and a measure as below. The pbix is attached in the end.

    FormattedMonthYear = VALUE(FORMAT(Sheet1[Month Year],"yyyymm"))
    Qty Remaining = 
    var _base =
    CALCULATE(
        AVERAGE(Sheet1[Curr Released Inv Qty (Base qty)]),
        FILTER(
            ALL(Sheet1),
            Sheet1[Item #] = SELECTEDVALUE(Sheet1[Item #])
        )
    )
    var _required = 
    CALCULATE(
        SUM(Sheet1[Required ( same as Total Fqty)]),
        FILTER(
            ALL(Sheet1),
            Sheet1[Item #] = SELECTEDVALUE(Sheet1[Item #])&&
            Sheet1[FormattedMonthYear]<=SELECTEDVALUE(Sheet1[FormattedMonthYear])
        )
    )
    return
    _base-_required

     

    Result:

     

    Best Regards

    Allan

     

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

  • v-alq-msft's avatar
    v-alq-msft
    Community Support

    Hi, Anonymous 

     

    If you take the answer of someone, please mark it as the solution to help the other members who have same problems find it more quickly. If not, let me know and I'll try to help you further. Thanks.

     

    Best Regards

    Allan

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      thanks for trying, but the solution mentioned didnt work for the second item, which has to reset the calculation. I have manged to write a measure calculation on my own. 

      • v-alq-msft's avatar
        v-alq-msft
        Community Support

        Hi, Anonymous 

         

        If possible, could you please share the measure to help the other members who have same problems find it more quickly. Thanks.

         

        Best Regards

        Allan