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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Kate_newmember
New Member

Date and Season Dax help

Hello All,

I am very new to Power bi.

I have a Date and Season and Fact Table.

They are connected with 1-many reations.

In seasons table I have 2 seasons(F and S)
The season F is from previous year March to November (Season F22  =  March 2021- Nov 2021 )

The season S is from previous year December to Feb (Season F22  =  December 2021- Feb 2021 )


My ask is , If user selects a date then it shoud show the current year(whate ever is the selected date) and previous year dates in a  bar chart to compare data. Dates are not sequential we need to compare to the closest dates

This is to compare data by dates with season.

Kate_newmember_0-1678202904815.png

TestData 

 

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Kate_newmember ,

I can't download your pbix file. 

But you can have a try.

Disabling relationships between date tables and other tables. Then create a measure.

measure =
VAR _selectedvalue =
    SELECTEDVALUE ( date[date] )
VAR _1yearago =
    EDATE ( _selectedvalue, -12 )
VAR _value =
    CALCULATE (
        MAX ( table[value] ),
        FILTER ( ALL ( table ), table[date] = _1yearago )
    )
VAR _datediff =
    DATEDIFF ( _1yearago, MAX ( date[date] ), DAY )
VAR _minx =
    MINX ( ALL ( date ), _datediff )
VAR _minxvalue =
    CALCULATE (
        MAX ( table[value] ),
        FILTER ( ALL ( table ), table[date] = _minx )
    )
RETURN
    IF ( _value = blank, _minxvalue, _value )

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Polly

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

1 REPLY 1
Anonymous
Not applicable

Hi @Kate_newmember ,

I can't download your pbix file. 

But you can have a try.

Disabling relationships between date tables and other tables. Then create a measure.

measure =
VAR _selectedvalue =
    SELECTEDVALUE ( date[date] )
VAR _1yearago =
    EDATE ( _selectedvalue, -12 )
VAR _value =
    CALCULATE (
        MAX ( table[value] ),
        FILTER ( ALL ( table ), table[date] = _1yearago )
    )
VAR _datediff =
    DATEDIFF ( _1yearago, MAX ( date[date] ), DAY )
VAR _minx =
    MINX ( ALL ( date ), _datediff )
VAR _minxvalue =
    CALCULATE (
        MAX ( table[value] ),
        FILTER ( ALL ( table ), table[date] = _minx )
    )
RETURN
    IF ( _value = blank, _minxvalue, _value )

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Polly

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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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