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

Prepping for a Fabric certification exam? Join us for a live prep session with exam experts to learn how to pass the exam. Register now.

Reply
alearner
Helper I
Helper I

Measure as a Slicer for a Line Chart

Hello. First of all a thanks to all who are helping me out with the queries that I have in DAX and as such help me train on DAX,

 

Looking for a solution for a readblocker that I am in. 

 

I have a table which has the NAV for the last 13+ years. There are Multiple Schemes and the NAV for each day of the year. I also have a Date Table and the Date Table has a relationship with the NAV table. 

 

The Sample Tables look like below. 

NAV Table:

navDatenavValuenavValueAdjustedFundHouseSchemeName
01-01-201356.1756.17ICICI Prudential Mutual FundICICI Prudential Equity & Debt Fund - Direct Plan - Growth
02-01-201356.6156.61ICICI Prudential Mutual FundICICI Prudential Equity & Debt Fund - Direct Plan - Growth
03-01-201356.856.8ICICI Prudential Mutual FundICICI Prudential Equity & Debt Fund - Direct Plan - Growth
22-11-2023309.0981309.0981SBI Mutual FundSBI CONTRA FUND - DIRECT PLAN - GROWTH
23-11-2023309.1313309.1313SBI Mutual FundSBI CONTRA FUND - DIRECT PLAN - GROWTH
24-11-2023309.2942309.2942SBI Mutual FundSBI CONTRA FUND - DIRECT PLAN - GROWTH

 

Above is just a sample.

 

Similarly I have a Date Table also which has the dates. 

 

I have a line chart which is as below: 

 

alearner_0-1702194647647.png

Note currently the slicer that you see of 1, 2 and 5 years are not active and this is something that I am trying to achieve. I could have put in Year slicer but would not like to use that as there would be just too many years to select starting from 2013 to 8th Dec 2023. Depending upon what I select above I would like to go 1 year, 2 or 5 years from the Max date that is present in the NAV Table.

I have created a calculated table which has the value of the slicer. But the challange that I am facing is how do I change the Data of the x axis (Date from Date Table) to show only last 1 year from the current Max date in the NAV table. 

I tried using the below but it is not what I want. I tried for 1 year to check the output:

Selected KPI FOR Landing Page NAV =
    SWITCH('Summary Page SLICER'[Slicer Selected],
        1, CALCULATE(
    SUM(ALL_NAV[navValue]),
    DATESINPERIOD(
        'Date'[Date],
        MAX('Date'[Date]),
        -1,
        YEAR
    ))
 
and this is what I get. It simply goes back one year from the current year but the year at x axis remains the same.
alearner_1-1702195011253.png

 

The sample NAV table with more date can be found at the below link:

https://pastebin.com/edit/0EcLuH32 

2 REPLIES 2
lbendlin
Super User
Super User

I have created a calculated table which has the value of the slicer. 

You cannot create a calculated column or calculated table from a measure.  (Well, you can, but it makes no sense).

 

It needs to be the other way round - your measure needs to sense the selected value of a table (your year buckets) and then the measure needs to ba applied as a filter to the line chart.

I was finally able to achieve what I wanted using the below Measure for 1, 3 and 5 years. Now my chard dynamically changes the x axis as I select 1, 3 and 5 years.

 

Selected KPI FOR Landing Page NAV =
var maxdt1= CALCULATE(MAX(ALL_NAV[navDate]), all(ALL_NAV)) - 365
var maxdt3= CALCULATE(MAX(ALL_NAV[navDate]), all(ALL_NAV)) - 1095
var maxdt5= CALCULATE(MAX(ALL_NAV[navDate]), all(ALL_NAV)) - 1825
   return SWITCH('Summary Page SLICER'[Slicer Selected],
        1, CALCULATE(sum(ALL_NAV[navValue]), ALL_NAV[navDate] >= maxdt1),
        3, CALCULATE(sum(ALL_NAV[navValue]), ALL_NAV[navDate] >= maxdt3),
        5, CALCULATE(sum(ALL_NAV[navValue]), ALL_NAV[navDate] >= maxdt5),
        sum(ALL_NAV[navValue]))

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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

Top Solution Authors