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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
harshadrokade
Post Partisan
Post Partisan

Column chart with most recent two date values

@Ashish_Mathur Since you alredy created a pbix file on this, sharing this with you.

 

I have below data & I have slicers on Month, Student name & Subject name

 

I want a column chart created that will show values for selected date & most recent date after selected date.

 

E.g. If I selected Student as A, Subject as ABC2 & date as 1 Dec 2020 in the slicers, the column chart shoudl show the two values on column chart as below-


Date-1 Dec 2020 , Value-100

Date-1 Aug 2020, Value- 90

 

PLs also note that I also have some other visuals getting filtered based on Date slicer.

 

Month-DD/MM/YYYYValueStudent nameSubject name
01/01/2020100AABC1
01/03/202080AABC1
01/08/202090AABC1
01/12/202070AABC1
01/01/202070AABC2
01/03/202080AABC2
01/08/202090AABC2
01/12/2020100AABC2
01/01/202010BABC1
01/03/2020100BABC1
01/08/202070BABC1
01/12/202040BABC1
01/01/202030BABC2
01/03/202080BABC2
01/08/202030BABC2
01/12/202010BABC2
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @harshadrokade ,

I updated the sample pbix file, please check whether it can return your expected result. You can find the details in the attachment.

1. Create a date dimension table(DO NOT create any relationship with your fact table)

Date = VALUES('Table'[Month-DD/MM/YYYY])

2. Update the formula of measure [] as below

Most recent two date values = 
VAR _selstu =
    SELECTEDVALUE ( 'Table'[Student name] )
VAR _selsubject =
    SELECTEDVALUE ( 'Table'[Subject name] )
VAR _maxdate =
    SELECTEDVALUE ( 'Date'[Month-DD/MM/YYYY] )
VAR _secondmdate =
    CALCULATE (
        MAX ( 'Table'[Month-DD/MM/YYYY] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Month-DD/MM/YYYY] < _maxdate )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER ( 'Table', 'Table'[Month-DD/MM/YYYY] IN { _maxdate, _secondmdate } )
    )

3. Apply the date field as slicer option to replace the field in fact table

yingyinr_0-1648542647842.png

Best Regards

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

Hi @harshadrokade ,

I created a sample pbix file(see attachment), please check whether that is what you want. You can create a measure as below:

Most recent two date values = 
VAR _selstu =
    SELECTEDVALUE ( 'Table'[Student name] )
VAR _selsubject =
    SELECTEDVALUE ( 'Table'[Subject name] )
VAR _maxdate =
    CALCULATE (
        MAX ( 'Table'[Month-DD/MM/YYYY] ),
        REMOVEFILTERS ( 'Table'[Month-DD/MM/YYYY] )
    )
VAR _secondmdate =
    CALCULATE (
        MAX ( 'Table'[Month-DD/MM/YYYY] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Student name] = _selstu
                && 'Table'[Subject name] = _selsubject
                && 'Table'[Month-DD/MM/YYYY] < _maxdate
        )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Student name] = _selstu
                && 'Table'[Subject name] = _selsubject
                && 'Table'[Month-DD/MM/YYYY] IN { _maxdate, _secondmdate }
        )
    )

yingyinr_0-1648536317611.png

Best Regards

Thanks for this @Anonymous . I want the column chart to show two columns on the chart, first the selected date & the second the 2nd recent date after selected date

 

Example, If I selected Dec 20 on slicer value & we have Latest date after Dec 20 as Oct 20, then the chart should show values as below-

harshadrokade_0-1648540915850.png

 

If I selected Feb 21 on slicer value & we have Latest date after Feb 21 as Jan 21, then the chart should show values of Feb 21 & Jan 21.

Anonymous
Not applicable

Hi @harshadrokade ,

I updated the sample pbix file, please check whether it can return your expected result. You can find the details in the attachment.

1. Create a date dimension table(DO NOT create any relationship with your fact table)

Date = VALUES('Table'[Month-DD/MM/YYYY])

2. Update the formula of measure [] as below

Most recent two date values = 
VAR _selstu =
    SELECTEDVALUE ( 'Table'[Student name] )
VAR _selsubject =
    SELECTEDVALUE ( 'Table'[Subject name] )
VAR _maxdate =
    SELECTEDVALUE ( 'Date'[Month-DD/MM/YYYY] )
VAR _secondmdate =
    CALCULATE (
        MAX ( 'Table'[Month-DD/MM/YYYY] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Month-DD/MM/YYYY] < _maxdate )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER ( 'Table', 'Table'[Month-DD/MM/YYYY] IN { _maxdate, _secondmdate } )
    )

3. Apply the date field as slicer option to replace the field in fact table

yingyinr_0-1648542647842.png

Best Regards

Thanks @Anonymous sir a lot sir for all you help.

 

This has worked sir but since I am not creating relationship bewteen date dimension table & fact table, my other visuals that are derived from fact table are not getting updated when I change the date which is derived from date dimention table.

 

How to manage to filter other visuals from Fact table sir with Date slicer?

Anonymous
Not applicable

Hi @harshadrokade ,

If there are other visuals in the report and you need to dynamically display values based on the filtering of the date slicer, you may need to change the fields or the formulas for measures applied under the Values option in those visuals ( For example, add the condition: 'Facttable'[Date] between min('Datedimension'[ Date]) and max('Datedimension'[Date]) ). You can share a simplified pbix file with me and I will see if there is another more suitable solution later. Thank you.

Best Regards

harshadrokade
Post Partisan
Post Partisan

HI @Greg_Deckler 

 

Your post on below link helped me to filter the months based on other calendar table slicer. The only issue I am facing is that since the slicer value is selected from other delinked table, the other visuals that I have created from sales table are not getting filetered when I change the date. How can I manage this?

https://community.powerbi.com/t5/Desktop/Show-the-last-X-years-based-on-the-current-Selection-of-the...

 

 

Ashish_Mathur
Super User
Super User

Hi,

See this post - Solved: Re: Dax to get 2nd most recent value of selected d... - Microsoft Power BI Community


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thanks @Ashish_Mathur 
Actually I want to create a column chart. I am unable to understand how to use these measures on the column chart. I think I need a filter that will filter my month axis by providing latest & 2nd most recent month. How can I achive that sir?

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors