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

The FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now

Reply
sahildoshi
Helper I
Helper I

Power BI : Past N days in Matrix

Hi All,

 

I have a requirement where I need to display past 30 days trend in Matrix visual based on selection done from date filter. For example, if 13th July is selected, then the Matrix should display dates from 13th July to 13th June in Descending order. Similarly, if 1st July is selected then Matrix should display dates from 1st July to 1st June.

 

Below is my sample dataset.

 

pastNdays_Input.png

 

Below is the expected output :

pastNdays_Output.png

 

I have tried below measure till now but no success. 

30 days Value =
var _value = CALCULATE(SUM('fact'[Sales]), ALL('date'[date]))
var _sel = SELECTEDVALUE('date'[date])
var _selected = CALCULATE(MAX('fact'[fact_date]), 'fact'[fact_date] = _sel, ALL('date'[date]))
var _mindate = _selected - 5

return CALCULATE(_value, 'fact'[fact_date] <= _selected && 'fact'[fact_date] > _mindate)


Current Output irrespective of what date I select in filter.

pastNdays_Output2.png

Please help me out here @GilbertQ @amitchandak @Greg_Deckler 

1 ACCEPTED SOLUTION

@sahildoshi I just realized what you actually want. PBIX file is attached below signature.

Selector = 
    VAR _sel = MAX('Calendar'[date])
    VAR _min = _sel - 5
    VAR _date = MAX('Transactions'[fact_date])
RETURN
    IF(_date >= _min && _date <= _sel,SUM(Transactions[Sales]),BLANK())


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

5 REPLIES 5
Greg_Deckler
Community Champion
Community Champion

@sahildoshi Maybe:

30 days Value =
var _sel = SELECTEDVALUE('date'[date])
var _mindate = _selected - 5
return SUMX(FILTER(ALL('fact'),[fact_date] <= _sel && 'fact'[fact_date] > _mindate),'fact'[Sales])


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler , thank you for your response. I tried your measure but it just sums up sales of period in consideration. Please refer below snapshot when date selected is 12 Jul. It sums up sales from 9 Jul to 12 Jul and displays for all dates.

pastNdays_Output3.png

@sahildoshi I just realized what you actually want. PBIX file is attached below signature.

Selector = 
    VAR _sel = MAX('Calendar'[date])
    VAR _min = _sel - 5
    VAR _date = MAX('Transactions'[fact_date])
RETURN
    IF(_date >= _min && _date <= _sel,SUM(Transactions[Sales]),BLANK())


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler , thank you your solution it works. So the key part was the relationship between the tables, in my case the fact and calendar was connected. I'll have to create a copy  of transaction table (disconnected table) for this visual then.

@sahildoshi So where is the Date coming from in that table visual? From Date or Fact table? Also, is there a relationship between those two tables? If you can post the sample data you provided as text, I can mock up a quick PBIX and get it solved.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.