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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Gionedis
Helper I
Helper I

Same day Last Month - Month not continuous

Hello,

 

I have a column with number of customers of the day, i need to compare it with the same day last month, the problem is that i don't have all days in my table, i don't have weekends and holidays, because there are no customers these days. For these days i need to find the closest day.

Ex:

day 23/03/2023 (717) i want to compare with 23/02/2023 (817)

day 22/03/2023 (773) i want to compare with 17/02/2023 (758), because I don't have 22/02/2023 so the next available day is 17/02

 

Gionedis_0-1680286379860.png

 

Thanks

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I assume you have a date dim table in the model.

Please check the below picture and the attached pbix file. I tired to create a sample pbix file like below.

I hope the below can provide some ideas on how to create a solution for your datamodel.

 

Jihwan_Kim_0-1680292943790.png

 

Jihwan_Kim_1-1680293506639.png

 

 

Prev month value measure: =
VAR _prevmonthdate =
    CALCULATE ( MAX ( 'Calendar'[Date] ), DATEADD ( 'Calendar'[Date], -1, MONTH ) )
VAR _alldatesbeforeprevmonthdate =
    ADDCOLUMNS (
        FILTER ( ALL ( 'Calendar' ), 'Calendar'[Date] <= _prevmonthdate ),
        "@value", [Value measure:]
    )
VAR _nonblankvaluelatestdatebeforeprevmonthdate =
    MAXX (
        FILTER ( _alldatesbeforeprevmonthdate, [@value] <> BLANK () ),
        'Calendar'[Date]
    )
RETURN
    IF (
        NOT ISBLANK ( [Value measure:] ),
        CALCULATE (
            [Value measure:],
            'Calendar'[Date] = _nonblankvaluelatestdatebeforeprevmonthdate
        )
    )

 

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

View solution in original post

3 REPLIES 3
CNENFRNL
Community Champion
Community Champion

CNENFRNL_0-1680295823210.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Jihwan_Kim
Super User
Super User

Hi,

I assume you have a date dim table in the model.

Please check the below picture and the attached pbix file. I tired to create a sample pbix file like below.

I hope the below can provide some ideas on how to create a solution for your datamodel.

 

Jihwan_Kim_0-1680292943790.png

 

Jihwan_Kim_1-1680293506639.png

 

 

Prev month value measure: =
VAR _prevmonthdate =
    CALCULATE ( MAX ( 'Calendar'[Date] ), DATEADD ( 'Calendar'[Date], -1, MONTH ) )
VAR _alldatesbeforeprevmonthdate =
    ADDCOLUMNS (
        FILTER ( ALL ( 'Calendar' ), 'Calendar'[Date] <= _prevmonthdate ),
        "@value", [Value measure:]
    )
VAR _nonblankvaluelatestdatebeforeprevmonthdate =
    MAXX (
        FILTER ( _alldatesbeforeprevmonthdate, [@value] <> BLANK () ),
        'Calendar'[Date]
    )
RETURN
    IF (
        NOT ISBLANK ( [Value measure:] ),
        CALCULATE (
            [Value measure:],
            'Calendar'[Date] = _nonblankvaluelatestdatebeforeprevmonthdate
        )
    )

 

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Works like a Charm Thanks, I'll study this formula to understand in the future, Thank you, my friend

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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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