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
tamiribas
Helper II
Helper II

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

4 REPLIES 4
tamiribas
Helper II
Helper II

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

 

 

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.