Forum Discussion

nor303's avatar
nor303
Helper III
2 years ago
Solved

Problem with showing objects that have data in a given period and calculate the percentage change

Hi, 

 

I want to see whichs object that have data for a given period. Then I want to see the percentage change on the total and also see have many objects thats increase or decrease in value or are unchanged. The data looks like this and my preferred output. I will show this in Powerbi with maybe a matrix and som charts and cards. Any suggestions on how to solve this? Ive looked at both youtube and chatgtp without luck. (In the tables I want need the objects, just the sums, they are only there to show how I think, but a drill down could be nice if someone wants to take a deeper look at it).

 

Cheers!

 

 PeriodeObjectValue   
 20232290   
 20232385   
 20232470   
 20232565   
 20232640   
 20222295   
 20222392   
 20222475   
 20222570   
 20222645   
 20212297   
 20212392   
 20212474   
 20212778   
 20202294   
 20202390   
 20202575   
       
       
 How many are represented in all periods2    
       
 Object/Year2023202220212020 
 2290959794 
 2385929290 
 Sum175187189184 
 Change-6,42 %-1,06 %2,72 %  
       
 How many are repsented in the 3 last periods 
 3     
 Object/Year202320222021  
 22909597  
 23859092  
 24707574  
 Sum245260263  
 Change-5,77 %-1,14 %   
       
       
 Object/Year2023202220212020 
 22DownDownUPNo change
 23DownNo changeUPNo change
 No change 0102 
 Up0020 
 Down2100 
       
 How many are repsented in the 3 last periods 
 3     
 Object/Year202320222021  
 22DownDownNo change 
 23DownNo changeNo change 
 24DownUpNo change 
 No change 013  
 Up010  
 Down310  
       
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi nor303 ,

     

    I think you can try code as below to use virtual table in your measure to achieve your goal.

    Measure = 
    VAR _Generate =
        ADDCOLUMNS (
            GENERATE ( ALLSELECTED('DimObject & Calculation'), ALLSELECTED(DimPerioder[Periode])),
            "Result",
                CALCULATE (
                    SUM ( 'Table'[Value] ),
                    FILTER (
                        'Table',
                        'Table'[Object] = EARLIER ( [Object] )
                            && 'Table'[Periode] = EARLIER ( [Periode] )
                    )
                ) + 0
        )
    VAR _Step1 =
        ADDCOLUMNS (
            _Generate,
            "Product", PRODUCTX ( FILTER ( _Generate, [Object] = EARLIER ( [Object] ) ), [Result] )
        )
    VAR _Step2 =
        FILTER ( _Step1, [Product] <> 0 || [Object] IN { "Sum", "Change" } )
    VAR _Step3 =
        ADDCOLUMNS (
            _Step2,
            "Final",
                SWITCH (
                    [Object],
                    "Sum", SUMX ( FILTER ( _Step2, [Periode] = EARLIER ( [Periode] ) ), [Result] ),
                    "Change",
                        VAR _LastPeriod =
                            SUMX ( FILTER ( _Step2, [Periode] = EARLIER ( [Periode] ) - 1 ), [Result] )
                        VAR _Current =
                            SUMX ( FILTER ( _Step2, [Periode] = EARLIER ( [Periode] ) ), [Result] )
                        RETURN
                            DIVIDE ( _Current - _LastPeriod, _LastPeriod ),
                    [Result]
                )
        )
    RETURN
    SUMX(FILTER(_Step3,[Object] = MAX('DimObject & Calculation'[Object]) && [Periode] = MAX(DimPerioder[Periode])),[Final])

    Dynamic Format:

    IF(MAX('DimObject & Calculation'[Object]) = "Change","0.00%;-0.00%;0.00%","0")

    Result is as below.

    You can download my sample file to learn more details.

     

    Best Regards,
    Rico Zhou

     

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

     

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi nor303 ,

     

    I think you can try code as below to use virtual table in your measure to achieve your goal.

    Measure = 
    VAR _Generate =
        ADDCOLUMNS (
            GENERATE ( ALLSELECTED('DimObject & Calculation'), ALLSELECTED(DimPerioder[Periode])),
            "Result",
                CALCULATE (
                    SUM ( 'Table'[Value] ),
                    FILTER (
                        'Table',
                        'Table'[Object] = EARLIER ( [Object] )
                            && 'Table'[Periode] = EARLIER ( [Periode] )
                    )
                ) + 0
        )
    VAR _Step1 =
        ADDCOLUMNS (
            _Generate,
            "Product", PRODUCTX ( FILTER ( _Generate, [Object] = EARLIER ( [Object] ) ), [Result] )
        )
    VAR _Step2 =
        FILTER ( _Step1, [Product] <> 0 || [Object] IN { "Sum", "Change" } )
    VAR _Step3 =
        ADDCOLUMNS (
            _Step2,
            "Final",
                SWITCH (
                    [Object],
                    "Sum", SUMX ( FILTER ( _Step2, [Periode] = EARLIER ( [Periode] ) ), [Result] ),
                    "Change",
                        VAR _LastPeriod =
                            SUMX ( FILTER ( _Step2, [Periode] = EARLIER ( [Periode] ) - 1 ), [Result] )
                        VAR _Current =
                            SUMX ( FILTER ( _Step2, [Periode] = EARLIER ( [Periode] ) ), [Result] )
                        RETURN
                            DIVIDE ( _Current - _LastPeriod, _LastPeriod ),
                    [Result]
                )
        )
    RETURN
    SUMX(FILTER(_Step3,[Object] = MAX('DimObject & Calculation'[Object]) && [Periode] = MAX(DimPerioder[Periode])),[Final])

    Dynamic Format:

    IF(MAX('DimObject & Calculation'[Object]) = "Change","0.00%;-0.00%;0.00%","0")

    Result is as below.

    You can download my sample file to learn more details.

     

    Best Regards,
    Rico Zhou

     

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