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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
chrisdavila
Frequent Visitor

Dynamic compare two scenarios based off selection

Creating a financial report that will have a few different scenarios (years) that will need to be compared across a few different metrics. User would come in and select which two years they want to see compared and then see totals for billings, revenue etc and the variances. i can attach a sample report. 

 

The selection would be any two years on the year column. 

2 ACCEPTED SOLUTIONS
chrisdavila
Frequent Visitor

entityYYYYRegionMarketClient_BillingsClient_Net_RevenueClient_Total_Gross_Revenue
5frFRANCcon2019EMEAFrance7215.0017215.0017215.001
5grGRBGMcon2019EMEAGreece1139903.943169980.721169980.721
5totANNALECT2019GlobalGlobal-0.3300
5totPUERT2019LATAMPuerto Rico000
5xtotBELGM2019EMEABelgium686262.4829564.94429564.944
2clCHILE2019LATAMChile0-83248.259-83248.259
5frFRANCcon2019EMEAFrance48257.70948257.70948257.709
5totNZLND2019APACNew Zealand000
5xtotBELGM2019EMEABelgium490480.47935611.35135611.351
5totOUTDR2019North AmericaUSA761721512151
5totPHDUS2019North AmericaUSA1881256131983131983
5totRESOL2019North AmericaUSA344556.0995790.55333039
5totICON2019North AmericaUSA4185-78304185
5frFRANCcon2019EMEAFrance000
5totASTRL2019APACAustralia127774.281127774.138127774.138
5vnVIETNcon2019APACVietnam631129.28122485.76622485.766
5xtotBELGM2019EMEABelgium26706.153997.8193997.819
5totOUTDR2019North AmericaUSA13907408304864304864
5dnDNMRKcon2019EMEADenmark000
5grGREECcon2019EMEAGreece438234.409316254.77316254.77
5totOUTDR2019North AmericaUSA4222922004120041
5totMOBIL2019EMEAUnited Kingdom000
5totUKGRP2019EMEAUnited Kingdom063424.81763424.817

View solution in original post

PaulDBrown
Community Champion
Community Champion

Ok, here are two possible ways of going about this.
The first is using the default matrix capabilities; this method will have a better performance but the metrics' headers are less clear.

TRaditional result.jpg
The second involves creating a specific table layout which recreates the measures displayed to be used as the matrix header. It provides more clarity at the expense of performance possibly (my sample dataset is minute so I can't really compare the performances of both solutions).

Custom Result.jpg

 

So...

Option 1: Default matrix capabilities.

We need two tables for "Year" to be able to compare the values. One of these tables has a regular One-to-many active relationship with the fact table; the second Year table's relationship is inactive. The model looks like this:

TRaditional.jpg

 The measures for each metric follow these patterns:
For the first Year selection.

 

Client Billings = 
SUM(FTable[Client_Billings])

 

For the comparison Year selection:

 

Comp Billings =
CALCULATE (
    [Client Billings],
    REMOVEFILTERS ( DYear[Year] ),
    USERELATIONSHIP ( VYear[Year], FTable[Year] )
)

 

and the % var between both years:

 

Billings % var =
SWITCH (
    TRUE (),
    AND ( ISBLANK ( [Client Billings] ), ISBLANK ( [Comp Billings] ) ), BLANK (),
    AND ( [Client Billings] = 0, [Comp Billings] = 0 ), 0,
    DIVIDE ( [Client Billings], [Comp Billings] ) - 1
)

 

The matrix is set up as follows, with each individual measure set in order in the values bucket:

default layout.jpg

 

 

 

To get:
Default.gif

 

Option 2: Custom Header to show the columns by years

The setup requires creating a custom table to use as the matrix header. Firstly we need a list of the measures and their respective order. (copy and paste from Excel or use the "Enter Data" option to create it):

header measures.jpg

We then need to add the Years from the model (Crossjoin) to create both the actual header needed in the matrix and a sorting column. This is all done in Power Query:

Header Table.jpg

 Leave this table unrelated in the model. The model looks like this:

Custom model.jpg

We only need to create one measure, referencing the measures we have already created, which is the one we will use for the matrix:

 

For Matrix =
SWITCH (
    TRUE (),
    ISBLANK ( [Client Billings] ) && ISBLANK ( [Comp Billings] )
        && ISBLANK ( [Net Revenue] ), BLANK (),
    AND (
        MAX ( Header[HYear] ) = SELECTEDVALUE ( DYear[Year] ),
        MAX ( Header[Order] ) = 1
    ), FORMAT ( [Client Billings], "Currency" ),
    AND (
        MAX ( Header[HYear] ) = SELECTEDVALUE ( VYear[Year] ),
        MAX ( Header[Order] ) = 2
    ), FORMAT ( [Comp Billings], "Currency" ),
    AND (
        MAX ( Header[HYear] ) = SELECTEDVALUE ( DYear[Year] ),
        MAX ( Header[Order] ) = 3
    ), FORMAT ( [Billings % var], "Percent" ),
    AND (
        MAX ( Header[HYear] ) = SELECTEDVALUE ( DYear[Year] ),
        MAX ( Header[Order] ) = 4
    ), FORMAT ( [Gross Revenue], "Currency" ),
    AND (
        MAX ( Header[HYear] ) = SELECTEDVALUE ( VYear[Year] ),
        MAX ( Header[Order] ) = 5
    ), FORMAT ( [Comp Gross Revenue], "Currency" ),
    AND (
        MAX ( Header[HYear] ) = SELECTEDVALUE ( DYear[Year] ),
        MAX ( Header[Order] ) = 6
    ), FORMAT ( [Gross Rev % Var], "Percent" ),
    AND (
        MAX ( Header[HYear] ) = SELECTEDVALUE ( DYear[Year] ),
        MAX ( Header[Order] ) = 7
    ), FORMAT ( [Net Revenue], "Currency" ),
    AND (
        MAX ( Header[HYear] ) = SELECTEDVALUE ( VYear[Year] ),
        MAX ( Header[Order] ) = 8
    ), FORMAT ( [Comp Net Revenue], "Currency" ),
    AND (
        MAX ( Header[HYear] ) = SELECTEDVALUE ( DYear[Year] ),
        MAX ( Header[Order] ) = 9
    ), FORMAT ( [Net Rev % Var], "Percent" )
)

 

We then set up the Matrix with the field fromt the Header Table as the columns, whatever dimension for the rows and the [For Matrix] measure as the values:
custom matrix layout.jpgTo get:
Custom.gif

 

So take your pick!

I've attached the sample PBIX file





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

8 REPLIES 8
PaulDBrown
Community Champion
Community Champion

Ok, here are two possible ways of going about this.
The first is using the default matrix capabilities; this method will have a better performance but the metrics' headers are less clear.

TRaditional result.jpg
The second involves creating a specific table layout which recreates the measures displayed to be used as the matrix header. It provides more clarity at the expense of performance possibly (my sample dataset is minute so I can't really compare the performances of both solutions).

Custom Result.jpg

 

So...

Option 1: Default matrix capabilities.

We need two tables for "Year" to be able to compare the values. One of these tables has a regular One-to-many active relationship with the fact table; the second Year table's relationship is inactive. The model looks like this:

TRaditional.jpg

 The measures for each metric follow these patterns:
For the first Year selection.

 

Client Billings = 
SUM(FTable[Client_Billings])

 

For the comparison Year selection:

 

Comp Billings =
CALCULATE (
    [Client Billings],
    REMOVEFILTERS ( DYear[Year] ),
    USERELATIONSHIP ( VYear[Year], FTable[Year] )
)

 

and the % var between both years:

 

Billings % var =
SWITCH (
    TRUE (),
    AND ( ISBLANK ( [Client Billings] ), ISBLANK ( [Comp Billings] ) ), BLANK (),
    AND ( [Client Billings] = 0, [Comp Billings] = 0 ), 0,
    DIVIDE ( [Client Billings], [Comp Billings] ) - 1
)

 

The matrix is set up as follows, with each individual measure set in order in the values bucket:

default layout.jpg

 

 

 

To get:
Default.gif

 

Option 2: Custom Header to show the columns by years

The setup requires creating a custom table to use as the matrix header. Firstly we need a list of the measures and their respective order. (copy and paste from Excel or use the "Enter Data" option to create it):

header measures.jpg

We then need to add the Years from the model (Crossjoin) to create both the actual header needed in the matrix and a sorting column. This is all done in Power Query:

Header Table.jpg

 Leave this table unrelated in the model. The model looks like this:

Custom model.jpg

We only need to create one measure, referencing the measures we have already created, which is the one we will use for the matrix:

 

For Matrix =
SWITCH (
    TRUE (),
    ISBLANK ( [Client Billings] ) && ISBLANK ( [Comp Billings] )
        && ISBLANK ( [Net Revenue] ), BLANK (),
    AND (
        MAX ( Header[HYear] ) = SELECTEDVALUE ( DYear[Year] ),
        MAX ( Header[Order] ) = 1
    ), FORMAT ( [Client Billings], "Currency" ),
    AND (
        MAX ( Header[HYear] ) = SELECTEDVALUE ( VYear[Year] ),
        MAX ( Header[Order] ) = 2
    ), FORMAT ( [Comp Billings], "Currency" ),
    AND (
        MAX ( Header[HYear] ) = SELECTEDVALUE ( DYear[Year] ),
        MAX ( Header[Order] ) = 3
    ), FORMAT ( [Billings % var], "Percent" ),
    AND (
        MAX ( Header[HYear] ) = SELECTEDVALUE ( DYear[Year] ),
        MAX ( Header[Order] ) = 4
    ), FORMAT ( [Gross Revenue], "Currency" ),
    AND (
        MAX ( Header[HYear] ) = SELECTEDVALUE ( VYear[Year] ),
        MAX ( Header[Order] ) = 5
    ), FORMAT ( [Comp Gross Revenue], "Currency" ),
    AND (
        MAX ( Header[HYear] ) = SELECTEDVALUE ( DYear[Year] ),
        MAX ( Header[Order] ) = 6
    ), FORMAT ( [Gross Rev % Var], "Percent" ),
    AND (
        MAX ( Header[HYear] ) = SELECTEDVALUE ( DYear[Year] ),
        MAX ( Header[Order] ) = 7
    ), FORMAT ( [Net Revenue], "Currency" ),
    AND (
        MAX ( Header[HYear] ) = SELECTEDVALUE ( VYear[Year] ),
        MAX ( Header[Order] ) = 8
    ), FORMAT ( [Comp Net Revenue], "Currency" ),
    AND (
        MAX ( Header[HYear] ) = SELECTEDVALUE ( DYear[Year] ),
        MAX ( Header[Order] ) = 9
    ), FORMAT ( [Net Rev % Var], "Percent" )
)

 

We then set up the Matrix with the field fromt the Header Table as the columns, whatever dimension for the rows and the [For Matrix] measure as the values:
custom matrix layout.jpgTo get:
Custom.gif

 

So take your pick!

I've attached the sample PBIX file





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






chrisdavila
Frequent Visitor

entityYYYYRegionMarketClient_BillingsClient_Net_RevenueClient_Total_Gross_Revenue
5frFRANCcon2019EMEAFrance7215.0017215.0017215.001
5grGRBGMcon2019EMEAGreece1139903.943169980.721169980.721
5totANNALECT2019GlobalGlobal-0.3300
5totPUERT2019LATAMPuerto Rico000
5xtotBELGM2019EMEABelgium686262.4829564.94429564.944
2clCHILE2019LATAMChile0-83248.259-83248.259
5frFRANCcon2019EMEAFrance48257.70948257.70948257.709
5totNZLND2019APACNew Zealand000
5xtotBELGM2019EMEABelgium490480.47935611.35135611.351
5totOUTDR2019North AmericaUSA761721512151
5totPHDUS2019North AmericaUSA1881256131983131983
5totRESOL2019North AmericaUSA344556.0995790.55333039
5totICON2019North AmericaUSA4185-78304185
5frFRANCcon2019EMEAFrance000
5totASTRL2019APACAustralia127774.281127774.138127774.138
5vnVIETNcon2019APACVietnam631129.28122485.76622485.766
5xtotBELGM2019EMEABelgium26706.153997.8193997.819
5totOUTDR2019North AmericaUSA13907408304864304864
5dnDNMRKcon2019EMEADenmark000
5grGREECcon2019EMEAGreece438234.409316254.77316254.77
5totOUTDR2019North AmericaUSA4222922004120041
5totMOBIL2019EMEAUnited Kingdom000
5totUKGRP2019EMEAUnited Kingdom063424.81763424.817

Can you please post data covering several years? (Otherwise no year comparison is possible)





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






 

EntityYearBillingsNet RevPlacementGross Rev
5OMD_USA2019835176858.42879413229496.528823628.5
5OMD_USA2021110734833441509975.38 41509975.38
5OMD_USA2022120138713143230742.9 43230742.9

what you see above is that it will be pre filtered to one entity

If you can share a sample PBIX file (you can share the link from a cloud service such as OneDrive, Google Drive, Dropbox...) that would be great





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Yes I get that. What I mean is that the sample data you posted is 2019 data, so there is no way of setting up a working example which will showcase year comparisons, which is what you originally requested





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Like if they chose 2022 and 2021

 

Billings 2022Billings 2021Var $Var %Revenue 2022Revenue 2021Var$Var %
$2,214,728$2,428,931($214,203)-8.8%$161,881$169,822($7,940)-4.7%
$2,166,979$2,670,534($503,555)-18.9%$158,611$162,008($3,397)-2.1%
$2,118,540$1,909,052$209,48811.0%$128,230$128,157$730.1%
$1,199,792$1,491,702($291,910)-19.6%$116,792$150,954($34,161)-22.6%
$1,464,133$1,097,197$366,93633.4%$104,524$78,612$25,91133.0%
$688,568$693,241($4,674)-0.7%$100,258$69,041$31,21645.2%
$2,571,724$2,518,014$53,7102.1%$95,071$91,866$3,2053.5%
$1,386,870$1,229,554$157,31612.8%$92,826$96,726($3,900)-4.0%
$310,772$939,260($628,488)-66.9%$67,270$227,506($160,236)-70.4%
$563,914$681,810($117,896)-17.3%$47,662$52,473($4,811)-9.2%
$110,789$87,714$23,07526.3%$45,665$39,549$6,11615.5%
$244,178$228,595$15,5836.8%$44,483$44,968($484)-1.1%
$127,202$120,970$6,2325.2%$41,585$37,202$4,38311.8%
$294,939$343,728($48,789)-14.2%$36,720$38,968($2,248)-5.8%

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.