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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Slicer with if statement

I have a slicer that contains multiple quarters. I will like to have a formula where if i click on Q1 2020, the formula will sum up the revenue  of  the prior yr revenue (ie Q1 2019).  One of the cards will then show current qtr revenue & another one showing last year revenue of the same qtr, then i can calculate year over year. 

 

I had tried selectValue but it doesn't work. I hope to get some help & advice from the expert. 

 

thanks in adv! 

1 ACCEPTED SOLUTION
v-lid-msft
Community Support
Community Support

Hi @Anonymous ,

 

We can use two ways to meet your requirement.

First way,

  1. We need to create a table that contains date and quarter.
Dates = ADDCOLUMNS (
    CALENDAR ( "2018/1/1", "2020/12/31" ),
    "Year Quarter Number", [date] * 100
        + QUARTER ( [date] ))
 

14.jpg

 

  1. Then we can create two measures to get the result,
current revenue =
var current__ = SELECTEDVALUE(Dates[Year Quarter Number])
return
CALCULATE(SUM('Table'[revenue]),'Table'[Year Quarter Number]=current__)

 

LQ revenue =
var current__ = SELECTEDVALUE(Dates[Year Quarter Number])
return
CALCULATE(SUM('Table'[revenue]),'Table'[Year Quarter Number]=current__-100)

15.jpg

 

The slicer uses Dates[Year Quarter Number].

 

Second way,

  1. We need to create a Dates table like first way.

 

  1. We can use the SAMPERIODLASTYEAR function to create the last year quarter measure.
Measure = CALCULATE(SUM('Table'[revenue]),SAMEPERIODLASTYEAR(Dates[Date]))

 

  1. At last we need to create a relationship between two tables based on date. Then we can get the result like this,
 

16.jpg17.jpg

 

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that we have shared?

 

BTW, the first way doesn’t need to create a relationship, and pbix file as attached.

 

Best regards,

 

Community Support Team _ Dong Li
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
v-lid-msft
Community Support
Community Support

Hi @Anonymous ,

 

We can use two ways to meet your requirement.

First way,

  1. We need to create a table that contains date and quarter.
Dates = ADDCOLUMNS (
    CALENDAR ( "2018/1/1", "2020/12/31" ),
    "Year Quarter Number", [date] * 100
        + QUARTER ( [date] ))
 

14.jpg

 

  1. Then we can create two measures to get the result,
current revenue =
var current__ = SELECTEDVALUE(Dates[Year Quarter Number])
return
CALCULATE(SUM('Table'[revenue]),'Table'[Year Quarter Number]=current__)

 

LQ revenue =
var current__ = SELECTEDVALUE(Dates[Year Quarter Number])
return
CALCULATE(SUM('Table'[revenue]),'Table'[Year Quarter Number]=current__-100)

15.jpg

 

The slicer uses Dates[Year Quarter Number].

 

Second way,

  1. We need to create a Dates table like first way.

 

  1. We can use the SAMPERIODLASTYEAR function to create the last year quarter measure.
Measure = CALCULATE(SUM('Table'[revenue]),SAMEPERIODLASTYEAR(Dates[Date]))

 

  1. At last we need to create a relationship between two tables based on date. Then we can get the result like this,
 

16.jpg17.jpg

 

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that we have shared?

 

BTW, the first way doesn’t need to create a relationship, and pbix file as attached.

 

Best regards,

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Thank you so much Dong_Li.  Option 2 works! I now have another issue & hope you can guide me... i wanted to show Year Over Year Change as a % i tried  creating a quick measure by dividng 'Table' [revenue] with [LY Org $]  but it returns blank. 

LY Org $ = CALCULATE(SUM('Table'[revenue]),SAMEPERIODLASTYEAR(Dates[Date]))

 

parry2k
Super User
Super User

@Anonymous there are many solutions/posts on time intelligence, the key here is to add calendar dimension in your model and mark it as date table and then use time intelligence functions for the measure.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.