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
Anonymous
Not applicable

Variance based on Period selected in Slicer

DateValueNameCountry
1/1/2021542CostUS
1/2/2021125CostUS
1/3/2021634CostUS
... (up to 31/12/2022 for example)   
1/1/2021857Cost2US
1/2/2021523Cost2US
1/3/2021109Cost2US
... ... (up to 31/12/2022 for example)   

 

I have a table with the date column, values, the name of the value and the country

 

I would like to build a table and slicers that shows the value of the selected month (e.g. 1/2/2021) and display 1) the original value in the table, 2) the variance of the value based on the previous month. 

For example, in the slicer, the month is 1/2/2021, the value of Cost of 1/2/2021 will subtract the value of 1/1/2021 to display the variance. Subsequently, in the slicer, the month is 1/6/2021, the value of Cost of 1/6/2021 will subtract the value of 1/5/2021. I want to make it dynamic, values to be changed when different options are selected in the slicer. Is this possible?

 

Thank you!

1 ACCEPTED SOLUTION

Hi @Anonymous ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want.

1. Create a single year dimension table as below(Do not create any relationship with your fact table)

yingyinr_1-1662456392652.png

2. Create a measure as below:

variance of years = 
VAR _selyear =
    SELECTEDVALUE ( 'Years'[Year] )
VAR _selcountry =
    SELECTEDVALUE ( 'Table'[Country] )
VAR _curyear =
    SELECTEDVALUE ( 'Table'[Year] )
VAR _selname =
    SELECTEDVALUE ( 'Table'[Name] )
VAR _preyvalue =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Year] = _curyear - 1
                && 'Table'[Country] = _selcountry
                && 'Table'[Name] = _selname
        )
    )
RETURN
    IF (
        _curyear >= _selyear - 1
            && _curyear <= _selyear
            && NOT ( ISBLANK ( _preyvalue ) ),
        SUM ( 'Table'[Value] ) - _preyvalue,
        BLANK ()
    )

yingyinr_0-1662456346433.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Community Support Team _ Rena
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

3 REPLIES 3
amitchandak
Super User
Super User

@Anonymous , Assume this DD /MM format and you need a month before value. Use an independnet date table to select the date

 

Value =

var _max1 = maxx(allselected('Date1'), 'Date1'[Date])

var _max = date(year(_max1), month(_max1) -1, Day(_max1) )

return

calculate(Sum(Table[Value]), filter(Table, Table[Date]= _max))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
Anonymous
Not applicable

@amitchandak thank you!

 

What if the criteria now is I want it to calculate the variance of 2022 and 2021. How do I do it?

Hi @Anonymous ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want.

1. Create a single year dimension table as below(Do not create any relationship with your fact table)

yingyinr_1-1662456392652.png

2. Create a measure as below:

variance of years = 
VAR _selyear =
    SELECTEDVALUE ( 'Years'[Year] )
VAR _selcountry =
    SELECTEDVALUE ( 'Table'[Country] )
VAR _curyear =
    SELECTEDVALUE ( 'Table'[Year] )
VAR _selname =
    SELECTEDVALUE ( 'Table'[Name] )
VAR _preyvalue =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Year] = _curyear - 1
                && 'Table'[Country] = _selcountry
                && 'Table'[Name] = _selname
        )
    )
RETURN
    IF (
        _curyear >= _selyear - 1
            && _curyear <= _selyear
            && NOT ( ISBLANK ( _preyvalue ) ),
        SUM ( 'Table'[Value] ) - _preyvalue,
        BLANK ()
    )

yingyinr_0-1662456346433.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Community Support Team _ Rena
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.