Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Calculation with multible variables in time

Hi all,

 

I am facing a problem in my Power BI File.

 

I am making a calculation based on some variable. What I am doing is comparing two numbers (current and past period) with each other to calculate the difference. To counter very small values there is a IF statement to filter these small values. My current Dimensionula is:

 

VAR LY_This_Period = CALCULATE(SUM('Table1'[Amount]),'Table1'[Dimension]=“Dimension”)

 

VAR LY_Past_Period = CALCULATE(SUM('Table1'[Amount]),PARALLELPERIOD('Calendar'[Date],-1,MONTH),'Table1'[Dimension]=“Dimension”)

 

VAR LY_Production_Period_DuringYear = CALCULATE(SUM('Table1'[Amount]),'Table1'[Dimension]=“Dimension”)-CALCULATE(SUM('Table1'[Amount]),PARALLELPERIOD('Calendar'[Date],-1,MONTH),'Table1'[Dimension]=“Dimension”)

 

RETURN

 

IF(AND(LY_Production_Period_DuringYear<0.049,LY_Production_Period_DuringYear>-0.049),BLANK(),

    IF(OR(LY_Past_Period=0,LY_This_Period=0),BLANK(),LY_Production_Period_DuringYear))

 

But the problem that I face is that in the month Januari it should not take the parral period but the first date of the year. Consequential it is needed that in February the calculation only is made based on the last date of January instead of the total calculation of January.

 

Do you have any tips or suggestions?

  • Hi, Anonymous 

     

    Based on the data you provide, you can try the following methods.

    Current value = SUM(Data[Value])
    Previous value = 
    Var PrevDate=MAXX(FILTER(ALL('Data'[Date],Data[Year]),'Data'[Date]<SELECTEDVALUE('Data'[Date])&&[Year]=SELECTEDVALUE(Data[Year])),'Data'[Date])
    Var Prevalue=CALCULATE([Current value],FILTER(ALL(Data),[Date]=PrevDate))
    Return
    Prevalue
    Outcome = IF([Previous value]<>BLANK(), [Current value]-[Previous value])

    The result of the calculation is different from the result you expect. Consider if there is a problem with your desired result calculation?

     

    Let me give you an example.

    But in your results.

    Please check if there is a problem with your result calculation in Excel, thank you.

     

    Best Regards,

    Community Support Team _Charlotte

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

11 Replies

  • Please provide sanitized sample data that fully covers your issue. I can only help you with meaningful sample data.
    Please paste the data into a table in your post or use one of the file services like OneDrive or Google Drive. Screenshots of your source data are not useful.
    Please show the expected outcome based on the sample data you provided. Screenshots of the expected outcome are ok.

    https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216
    https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

  • v-zhangti's avatar
    v-zhangti
    Community Support

    Hi, Anonymous 

     

    Can you provide sample data for testing? Sensitive information can be removed in advance. What kind of expected results do you expect? You can also show it with pictures.

     

    Best Regards,

    Community Support Team _Charlotte

    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

    v-zhangti lbendlin , sorry for my late responce I was on holiday.

     

    This is the problem. Hope it helpst, otherwise please let me know.

     

    • lbendlin's avatar
      lbendlin
      Super User

      Please provide sanitized sample data that fully covers your issue. I can only help you with meaningful sample data.
      Please paste the data into a table in your post or use one of the file services like OneDrive or Google Drive. Screenshots of your source data are not useful.

      • Anonymous's avatar
        Anonymous
        Not applicable

        You may use the data of the picture. This is a simplified sample. I can not share other data due to the GDPR.