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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
MyWeeLola
Helper II
Helper II

The curse of the previousmonth not working

Good afternoon

 

I used this code to create a date table

Date =
CALENDAR(
    MIN(tblMarch2024[Date Observation Entered]),
    MAX(tblMarch2024[Date Observation Entered])
    )
 
I set the table as a date table and the table now contains contiguous data from the 1/1/24 until 7/4/24 ( dd/mm/yy)
I then watched you tube, as you do, and added this abridged code to allow me to filter the underlying table
 
Date Periods =
var _sd = min('Date'[Date])
var _ed = max('Date'[Date])
RETURN

UNION(
    ADDCOLUMNS(
        DATESMTD('Date'[Date]),
        "Type","MTD",
        "Order",4
    ),
    ADDCOLUMNS(
        DATESQTD('Date'[Date]),
        "Type","QTD",
        "Order",6
    ),
    ADDCOLUMNS(
        CALENDAR(_ed-7,_ed),
        "Type","Last 7 Days",
        "Order",1
    ),
    ADDCOLUMNS(
        CALENDAR(_ed-14,_ed),
        "Type","Last 14 Days",
        "Order",2
    ),
    ADDCOLUMNS(
        PREVIOUSQUARTER('Date'[Date]),
        "Type","Last Qtr",
        "Order",7
    ),
    ADDCOLUMNS(
        PREVIOUSYEAR('Date'[Date]),
        "Type","Last Year",
        "Order",9
    ),
    ADDCOLUMNS(
        datesytd('Date'[Date]),
        "Type","This Year",
        "Order",8
    ),
    ADDCOLUMNS(
        PREVIOUSMONTH('Date'[Date]),
        "Type","Last Month",
        "Order",3
    )
)

 

 

I set the date columns to short date, and expected to sit back with it all working.

 

I added the date periods to a slicer and set the relationships.

Everything works, except for the ones which say"previous" first, The dates qtd, mtd and calendar work fine. however the others do not appear in the slicer and are not in the underlying table.

 

Can someone explain where I messed up, please?

 

Lola

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@MyWeeLola You may find this helpful - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000

Also, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...



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

4 REPLIES 4
Greg_Deckler
Community Champion
Community Champion

@MyWeeLola You may find this helpful - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000

Also, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...



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...

@Greg_Deckler 

 

Thank you, that resolved the issue and I can now resume with reckless abandon, thank you.

@Greg_Deckler 

 

Good morning, a few weeks ago you solved an issue I was having with time issue I was having.

 

I now have another quick question, where after reading you code, there may not have been a solution in there.

 

What I need is a a rolling date range which gives me the month, prior to the previous month.

 

For example. In May, the previous month is April. I need to display figures for March in one area and April in another as a comparison. As June approaches, I will then need to display April and May.

 

How would I achieve this? My thoughts are the use of a previous to previous month measure. How could I achieve that?

 

I look forward to hearing from you.

 

Lola

@Greg_Deckler  Much appreciated, I shall read it and respond shortly.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.