Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
nor303
Helper II
Helper II

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  
       
1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

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.

vrzhoumsft_0-1710832442604.png

vrzhoumsft_1-1710832449049.png

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.

 

View solution in original post

1 REPLY 1
v-rzhou-msft
Community Support
Community Support

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.

vrzhoumsft_0-1710832442604.png

vrzhoumsft_1-1710832449049.png

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.

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.