Forum Discussion

PBI5851's avatar
PBI5851
Helper V
5 years ago

Beginning and Ending value

Hello,

I am trying to generate a beginning value and ending value based on the below raw data. 

DateValCountFlag
1/1/2021100Incoming
1/1/2021-20Reject1
1/1/2021-10Reject2
1/1/2021-30Reject3
2/1/2021-5Reject1
2/1/2021-5Reject2
2/1/2021-10Reject3
3/1/202120Incoming
3/1/2021-30Reject1
4/1/202110Incoming

 

I am hoping to get the below structure. 

 JanFebMarApr
Beginnning 402010
Incoming10002010
Reject1-20-5-300
Reject2-10-500
Reject3-30-1000
Ending40201020

 

I thought of using PreviousMonth ,by creating the Ending Measure, but the Previous Month cant be done on a Measure and also without the correct Beginning value for Feb, the Ending is incorrect. Any recommendations of how to resolve this please. 

 

Thank you. 

3 Replies

  • PBI5851 , Create measure with help from date table

     

    Beginnning = CALCULATE(sum(Table[Count]),filter(allselected(date),date[date] <=maxx(date,dateadd(date[date]),-1,Month)))
    Ending = CALCULATE(sum(Table[Count]),filter(allselected(date),date[date] <=max(date[date])))

    Reject1 = calculate(sum(Table[Count]), datesmtd(Date[Date]), filter(Table, Table[Flag] ="Reject1"))
    Reject2 = calculate(sum(Table[Count]), datesmtd(Date[Date]), filter(Table, Table[Flag] ="Reject1"))
    Reject3 = calculate(sum(Table[Count]), datesmtd(Date[Date]), filter(Table, Table[Flag] ="Reject1"))
    Incoming = calculate(sum(Table[Count]), datesmtd(Date[Date]), filter(Table, Table[Flag] ="Incoming"))

     

    In matrix use show on row

    https://docs.microsoft.com/en-us/power-bi/visuals/desktop-matrix-visual

     

    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 :radacad sqlbi My Video Series Appreciate your Kudos.

    • PBI5851's avatar
      PBI5851
      Helper V

      Hi amitchandak,

      Thank you for the solution. However, this will work only if no other value were to be added to the table. Its my mistake of overlooking that scenario and  not providing that information in my question. If the incoming raw data was in this format where there are two more flags but do not account for the Beginning or End, then the "allselected" will not work. .

       

      DateValCountFlag
      1/1/2021100Incoming
      1/1/2021-20Reject1
      1/1/2021-10Reject2
      1/1/2021-30Reject3
      2/1/2021-5Reject1
      2/1/2021-5Reject2
      2/1/2021-10Reject3
      3/1/202120Incoming
      3/1/2021-30Reject1
      4/1/202110Incoming
      1/1/2130Contaminated
      2/1/2120user Error
      3/1/2110Manufacturing

       

      And the matrix should be


      How to achieve this ?

  • Please could you send me a pbix file using this solution. It doesnt work when i try it out.