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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
TomaKavi
Helper I
Helper I

how to get from selected value (slicer for Year/Month) -1 year in dax

Hello guys, 

I have a measure in dax which shows values for selected Year/Quarter in a slicer. I need to create another one which will show the results for the same Quarter but a Year back.Is there any dax function which might help ? I take the slicer from the column below so a YEAR -1 wont help me. 

 

TomaKavi_0-1696938857688.png

 

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

Hi @TomaKavi ,

 

If you want, for example, select 2022/Q3 in the slicer, but the result returns the value of 2021/Q3. Then the table of this slicer field needs to have no relationship to the table in your results visual.

Here's an example for reference.

The main table:

vstephenmsft_0-1697091588026.png

The YearQuarter table:

vstephenmsft_1-1697091605071.png

No relationship:

vstephenmsft_2-1697091620715.png

 

Create a measure as the visual-level filter.

Measure = var _year=SELECTEDVALUE('YearQuarter'[Year])
var _quarter=SELECTEDVALUE('YearQuarter'[Quarter2])
return IF(ISFILTERED('YearQuarter'[YearQuarter]),IF(_year-1=MAX('Table'[Year])&&_quarter=MAX('Table'[Quarter2]),1),1)

Now the table visual is from the main table. And the slicer is from the YearQuarter tabel.

vstephenmsft_3-1697091825891.png

Put the measure into the visual-level filters in the table visual. Set up show items when the values is 1.

vstephenmsft_4-1697091977154.png

Result:

vstephenmsft_5-1697091988846.png

 

 

 

Best Regards,

Stephen Tao

 

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

5 REPLIES 5
v-stephen-msft
Community Support
Community Support

Hi @TomaKavi ,

 

If you want, for example, select 2022/Q3 in the slicer, but the result returns the value of 2021/Q3. Then the table of this slicer field needs to have no relationship to the table in your results visual.

Here's an example for reference.

The main table:

vstephenmsft_0-1697091588026.png

The YearQuarter table:

vstephenmsft_1-1697091605071.png

No relationship:

vstephenmsft_2-1697091620715.png

 

Create a measure as the visual-level filter.

Measure = var _year=SELECTEDVALUE('YearQuarter'[Year])
var _quarter=SELECTEDVALUE('YearQuarter'[Quarter2])
return IF(ISFILTERED('YearQuarter'[YearQuarter]),IF(_year-1=MAX('Table'[Year])&&_quarter=MAX('Table'[Quarter2]),1),1)

Now the table visual is from the main table. And the slicer is from the YearQuarter tabel.

vstephenmsft_3-1697091825891.png

Put the measure into the visual-level filters in the table visual. Set up show items when the values is 1.

vstephenmsft_4-1697091977154.png

Result:

vstephenmsft_5-1697091988846.png

 

 

 

Best Regards,

Stephen Tao

 

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

hello, thanks, can work, but I have already created a different method. I have added another column in the date table, set 42022 for example as 4th Q for Y2022, set that as whole number, and in var where is selected specific Y/Q to use the new colum -1 and job done. But your solution will work as well

marcelsmaglhaes
Super User
Super User

Hey @TomaKavi 

You can create the column using the DAX bellow:

YearQuarter_LastYear = [date].[Year]-1 &"/Q" & [date].[QuarterNo]


Kind Regards,
Marcel


Regards,
Marcel Magalhães
Microsoft Power BI Official Partner
MCT | Certified PL-300 Power BI

If I've helped, don't forget to mark my post as a solution!
Imagem de fundo



maybe I am doing something wrong, but this wont work.

TomaKavi_0-1697005116409.png

 

Are you creating a Column? You need create a New Column in table date instead of a measure.

And, in instead of [date] you should use the name of your date column.


Regards,
Marcel Magalhães
Microsoft Power BI Official Partner
MCT | Certified PL-300 Power BI

If I've helped, don't forget to mark my post as a solution!
Imagem de fundo



Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.