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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
EgMorel
Helper I
Helper I

How to get sales and compare them with a custom calendar?

Hello everyone,

 

I want to find a way to calculate the sales from this month and compares it against the same month of an specific year, for example,


I have the sales between March 1st and March 13th 2023 and I want to compare it against 2019 same period but the difficulty is that the "Same Period in 2019" is not the "Same Period" what I mean is that it should be compared with a custom calendar, and to get the Customised 2019 calendar is subtract 2023 day with 1463 (i.e,. the comparableday of 2023/03/14 is 2019/03/12)

 

So, im going to explain my model with my tables in a simply way:

 

Actually, Im working with:

 

1. DETALLE_GRUPO (Sales Table with information from 2018 until today)

        - "Importe" (Sales in $)

        - "Fecha" (Date when the sales was made (normal calendar))

        - "Local" (Store where the sales was made)

 

2. Calendar2019 (Dates table)

       - "Custom2019" (the custom 2019 calendar substracting 2023 - 1463).

       - "2023" (normal calendar), so each row of 2023 should match with Custom2019.

 

I made a relationship with Calendar2019[2023] and DETALLE_GRUPO[Fecha].

 

I hope you can help me and sorry for my English.

 

Regards.

Eduardo

       

 

1 ACCEPTED SOLUTION

@EgMorel 

I think if you keep one date table and you create a 2nd (inactive) relationship between Calendar2019[Custom2019] and DETALLE_GRUPO[Fecha], then for 2019 the sales amount should calculate correctly using 

 

Sales 2019 = 

CALCULATE (

[Sales Amount],
USERELATIONSHIP ( Calendar2019[Custom2019], DETALLE_GRUPO[Fecha] )

)


Incase the result was all blank then try

 

Sales 2019 = 

CALCULATE (

[Sales Amount],
USERELATIONSHIP ( Calendar2019[Custom2019], DETALLE_GRUPO[Fecha] ),

CROSSFILTER ( Calendar2019[2023], DETALLE_GRUPO[Fecha], NONE )

)

View solution in original post

25 REPLIES 25
tamerj1
Super User
Super User

Hi @EgMorel 

Why not just keep in one table and create two relationships the use USERELATIONSHIP to switch between them?

Hi @tamerj1

 

Im not an expert in Power BI, so I came here asking for help. I tried different ways an no one works for me.
I tried working with just one Calendar Table with two columns but it doesnt works (I think a problem with relationships).

This is I want to achieve:

DateSales Store 1 (Normal Calendar)Sales Store 1 (Custom Calendar)
2023-03-01$1000$500 (this should be get from 2019-02-27)
2023-03-02$800$600 (this should be get from 2019-02-28)
   
   




@EgMorel 

I think if you keep one date table and you create a 2nd (inactive) relationship between Calendar2019[Custom2019] and DETALLE_GRUPO[Fecha], then for 2019 the sales amount should calculate correctly using 

 

Sales 2019 = 

CALCULATE (

[Sales Amount],
USERELATIONSHIP ( Calendar2019[Custom2019], DETALLE_GRUPO[Fecha] )

)


Incase the result was all blank then try

 

Sales 2019 = 

CALCULATE (

[Sales Amount],
USERELATIONSHIP ( Calendar2019[Custom2019], DETALLE_GRUPO[Fecha] ),

CROSSFILTER ( Calendar2019[2023], DETALLE_GRUPO[Fecha], NONE )

)

I will try this option but I didnt get the 1st relationship? because we are going to work with just one date table "Calendar2019" and "DETALLE_GRUPO", you mean have two relationship between the same tables?

@EgMorel 

Yes exactly. One would be active [2023] and one by default would be inactive [Custom2019]

@tamerj1,
I get the same result as the @johnt75's way, 2019Sales is your measure (with the first formula) and Sales2019 is the @johnt75 way

EgMorel_0-1678822822332.png

 

@EgMorel 

Place the months in the table to see it clearly. I would expect to see correct values for the first 3 months, however, after that you would still be able to see values under 2019 sales while 2023 sales should be blank being future months. If you to see values only upto date you can try

 

Sales 2019 = 

CALCULATE (

[Sales Amount],
USERELATIONSHIP ( Calendar2019[Custom2019], DETALLE_GRUPO[Fecha] ),

KEEPFILTERS ( Calendar2019[Custom2019] <= TODAY ( ) )

)

@tamerj1 this is the Result with the months as rows:

 

EgMorel_1-1678824481388.png

 

 

 

@EgMorel 

Sorry just noticed a mistake in the last formula. Please try 

Sales 2019 = 

CALCULATE (

[Sales Amount],
USERELATIONSHIP ( Calendar2019[Custom2019], DETALLE_GRUPO[Fecha] ),

KEEPFILTERS ( Calendar2019[2023] <= TODAY ( ) )

)

@tamerj1 the formula doesnt work, there is a third expression in CALCULATE?

@EgMorel 
What do you mean? Are you recieving an error? Yu may also try

Sales 2019 =
CALCULATE (
    [Sales Amount],
    USERELATIONSHIP ( Calendar2019[Custom2019], DETALLE_GRUPO[Fecha] ),
    FILTER ( Calendar2019, Calendar2019[2023] <= TODAY () )
)

Please provide a screenshot of the DAX and results hiding any sensetive data 

Sorry, my mistake, I forgot the comma after USERELATIONSHIP  hahaha 
Aparently, its working fine.Now, to be sure that the 2019Sales are working fine, How can I know that for example the date 2023-03-14 is compared against 2019-03-12? Can I obtain those values?

 

EgMorel_0-1678879176349.png

 

2019Sales = 
CALCULATE( DETALLE_GRUPO[TotalSales_2023], USERELATIONSHIP('Tabla Calendario'[Custom2019], DETALLE_GRUPO[Fecha]), KEEPFILTERS ('Tabla Calendario'[Date] <= TODAY ()) ) 

 

 

 

Thanks for your support, I gave myself too many turns and the solution was not that difficult 😔

 

@EgMorel 
No problem 🙂 
you can create hard codded measures like 

CALCULATE( [TotalSales_2023], 'Tabla Calendario'[Date] = DATE ( 2019, 3, 12 ) ) 

and place it in a card visual

@tamerj1, check this pls, the information opened by day and in card visual the last formula that points to 2019-03-12, I cant see that value in the 2019Sales, is that correct?

EgMorel_0-1678884297316.png

 

@EgMorel 
Ok, I think it is the time to ask you what is the difference between Calendar2019[Date] and Calendar2019[2023]? 😂

@tamerj1
Ok 😁, but in my Calendar table I only have "Date" as a normal calendar and Custom2019 as my Custom Calendar 😋. So, I realized that 2019Sales is OK because the sales in 2023-03-13 for 2019Calendar is $28,564,576 and if I look through the sales in that period (which is 2019-03-11) I get that value:

EgMorel_0-1678885967647.png

 

@EgMorel 

As expected. But which one is the latest formula with TODAY filter?

@tamerj1, Im using this one:

2019Sales = 
CALCULATE(
        DETALLE_GRUPO[TotalSales_2023],
        USERELATIONSHIP('Tabla Calendario'[Custom2019], DETALLE_GRUPO[Fecha]),
        KEEPFILTERS ('Tabla Calendario'[Date] <= TODAY ())
)

 

and this is the result:

EgMorel_0-1678886703291.png

 



 

 

@EgMorel 
Is it good or bad?

To exclude today you use

2019Sales = 
CALCULATE(
        DETALLE_GRUPO[TotalSales_2023],
        USERELATIONSHIP('Tabla Calendario'[Custom2019], DETALLE_GRUPO[Fecha]),
        'Tabla Calendario'[Date] < TODAY ()
)

is not good or bad, its PERFECT!!!

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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