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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
tamiribas
Resolver I
Resolver I

get a table with Min and Max Years upon selecting years from a slicer.

Hi

I am trying to get a table with Min and Max Years upon selecting two or more years from a date(Year) slicer.

I need help to get it working.

https://drive.google.com/file/d/1Haf8FMIICZOAiE839trkJgdJN1ZFLKrx/view?usp=sharing 

 

I have this Table measure:

MinMaxYears =
TREATAS(VALUES(dimDate[Year]),dimDate[Year])
and a slicer based on dimDate[Year]
 
(see link to file)
 

Thank you 

Tamir

2 ACCEPTED SOLUTIONS
Ritaf1983
Super User
Super User

Hi @tamiribas 
You can add a year column to the new table that you created :

MinMaxYears = values('dimDate'[Year])
Ritaf1983_0-1700249403545.png

Create a flag measure 

flag = if(max(MinMaxYears[Year])=max('dimDate'[Year])|| min('MinMaxYears'[Year])=min('dimDate'[Year]),1,0)
Put the year from the dim date at the slicer, the new table's year at the column on the table, and filter the table by the flag measure:
Ritaf1983_1-1700249587536.pngRitaf1983_2-1700249632189.png

Result :

Ritaf1983_3-1700249667704.png

PBIX is attached

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

 

 

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

View solution in original post

Fowmy
Super User
Super User

@tamiribas 

Please check the attached file, I created a measure and assigned at the visual filter on the Filter pane. I think you do not have to create a separate table here. Please check


Min or Max = 
VAR __MinYear = 
    CALCULATE(
        MIN(dimDate[Year]),
        ALLSELECTED( dimDate[Year] )
    )
VAR __MaxYear = 
    CALCULATE(
        MAX(dimDate[Year]),
        ALLSELECTED( dimDate[Year] )
    )
VAR __Result = 
           INT (  SELECTEDVALUE( dimDate[Year] ) in {__MinYear,__MaxYear} )
RETURN
    __Result

Fowmy_0-1700250407857.png

 





Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

4 REPLIES 4
tamiribas
Resolver I
Resolver I

Actually, the following file expresses better the requirement. 

https://drive.google.com/file/d/1sBYqwxXJrXE6fXhngeL_fglpzXFEJ8zP/view?usp=sharing 

 
The problem:
No matter what I choose in the DimDate[Year] slicer, I always get the first and last year of the dimDate table.

I didn't manage to force MIN Year and MAX year in the VARs.

I am using these values to show in the Calculated table.

 

SummaryTableMinMaxYears =

VAR _MinYearSelected = CALCULATE(MIN(dimDate[Year]))
VAR _MaxYearSelected = CALCULATE(MAX(dimDate[Year]))

VAR SalesAmountYearMin = CALCULATE(SUM(factSales[Amount]), 'dimDate'[Year] = _MinYearSelected)
VAR SalesAmountYearMax = CALCULATE(SUM(factSales[Amount]), 'dimDate'[Year] = _MaxYearSelected)
VAR TotalAmountYearMin = CALCULATE(COUNTROWS('factSales'), 'dimDate'[Year] = _MinYearSelected)
VAR TotalAmountYearMax = CALCULATE(COUNTROWS('factSales'), 'dimDate'[Year] = _MaxYearSelected)
VAR SalesAmountDiff = SalesAmountYearMax - SalesAmountYearMin
VAR TotalAmountDiff = TotalAmountYearMax - TotalAmountYearMin

RETURN
    UNION(
        ROW("Year", _MinYearSelected, "SalesAmount", SalesAmountYearMin, "TotalAmount", TotalAmountYearMin),
        ROW("Year", _MaxYearSelected, "SalesAmount", SalesAmountYearMax, "TotalAmount", TotalAmountYearMax),
        ROW("Year", "YoY"                   , "SalesAmount", SalesAmountDiff   ,      "TotalAmount", TotalAmountDiff)
    )
 
 

Thank you,

Tamir

Fowmy
Super User
Super User

@tamiribas 

Please check the attached file, I created a measure and assigned at the visual filter on the Filter pane. I think you do not have to create a separate table here. Please check


Min or Max = 
VAR __MinYear = 
    CALCULATE(
        MIN(dimDate[Year]),
        ALLSELECTED( dimDate[Year] )
    )
VAR __MaxYear = 
    CALCULATE(
        MAX(dimDate[Year]),
        ALLSELECTED( dimDate[Year] )
    )
VAR __Result = 
           INT (  SELECTEDVALUE( dimDate[Year] ) in {__MinYear,__MaxYear} )
RETURN
    __Result

Fowmy_0-1700250407857.png

 





Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Hi
It's very interesting! I would be happy to see the answer, I also met with a similar task

Ritaf1983
Super User
Super User

Hi @tamiribas 
You can add a year column to the new table that you created :

MinMaxYears = values('dimDate'[Year])
Ritaf1983_0-1700249403545.png

Create a flag measure 

flag = if(max(MinMaxYears[Year])=max('dimDate'[Year])|| min('MinMaxYears'[Year])=min('dimDate'[Year]),1,0)
Put the year from the dim date at the slicer, the new table's year at the column on the table, and filter the table by the flag measure:
Ritaf1983_1-1700249587536.pngRitaf1983_2-1700249632189.png

Result :

Ritaf1983_3-1700249667704.png

PBIX is attached

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

 

 

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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