March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hello,
I have a Dates table with 2 columns:
Values in Date column is unique, values in "related date in 2019" is not unique:
Date | related date in 2019 |
1/4/2020 | 1/5/2019 |
1/2/2021 | 1/5/2019 |
1/31/2020 | 2/1/2019 |
1/29/2021 | 2/1/2019 |
I have another table Sales:
date | store | sales |
2/1/2019 | A | 45 |
2/1/2019 | B | 95 |
1/5/2019 | A | 26 |
1/5/2019 | B | 11 |
1/4/2020 | A | 82 |
1/4/2020 | B | 12 |
1/31/2020 | A | 10 |
1/31/2020 | B | 66 |
1/29/2021 | A | 71 |
1/29/2021 | B | 27 |
1/2/2021 | A | 39 |
1/2/2021 | B | 25 |
The report I want is:
Date | Sales | sales in related dates in 2019 |
1/4/2020 | 94 | 37 |
1/2/2021 | 64 | 37 |
1/31/2020 | 76 | 140 |
1/29/2021 | 98 | 140 |
How to do the modeling and produce the desired output?
Thanks.
Solved! Go to Solution.
Hi @jj_0511 ,
I just removed the filter for the whole table (with "ALL ( table )" ) which assumably even removes the filter from the Date table.
This one here is probably the most correct one, but honestly, it depends a bit on how you wanna be using your measure.
SalesRelDates2019 = VAR CorrespondingDate2019 = SELECTEDVALUE ( 'Date'[related date in 2019] ) RETURN CALCULATE ( [SalesMeasure], ALL ( 'Date'[Date] ), 'Table'[Date] = ( CorrespondingDate2019 ) )
Did I answer your question❓➡️ Please, mark my post as a solution ✔️ |
Also happily accepting Kudos 🙂 |
Feel free to connect with me on LinkedIn! |
#proudtobeasuperuser |
Hi @jj_0511,
I'd probably just do one normal conenction from sales to date:
Next, I'd create a normal Sales measure:
And finally, the SalesRelDates2019 measure:
Did I answer your question❓➡️ Please, mark my post as a solution ✔️ |
Also happily accepting Kudos 🙂 |
Feel free to connect with me on LinkedIn! |
#proudtobeasuperuser |
@tackytechtom Thanks.
In your code: CALCULATE ( [SalesMeasure], ALL ( 'Table'), 'Table'[Date] = ( CorrespondingDate2019 )
what's purpose of ALL ( 'Table')?
why the following code does not work:
CALCULATE ( [SalesMeasure], ALL ( 'Table'[Date]), 'Table'[Date] = ( CorrespondingDate2019 )
Thanks.
Hi @jj_0511 ,
I just removed the filter for the whole table (with "ALL ( table )" ) which assumably even removes the filter from the Date table.
This one here is probably the most correct one, but honestly, it depends a bit on how you wanna be using your measure.
SalesRelDates2019 = VAR CorrespondingDate2019 = SELECTEDVALUE ( 'Date'[related date in 2019] ) RETURN CALCULATE ( [SalesMeasure], ALL ( 'Date'[Date] ), 'Table'[Date] = ( CorrespondingDate2019 ) )
Did I answer your question❓➡️ Please, mark my post as a solution ✔️ |
Also happily accepting Kudos 🙂 |
Feel free to connect with me on LinkedIn! |
#proudtobeasuperuser |
@jj_0511
Join date to the sales table:
I needed an intermediate measure for 2019 sales to use to get the total correct so there are 2.
The first one moves the 2019 related date to the sales table and calculates the amount.
Sales_2019_intermediate =
CALCULATE (
SUM ( Sales[sales] ),
ALL ( Dates ),
TREATAS ( VALUES ( Dates[related date in 2019] ), Sales[date] )
)
The second one uses the first and calcualtes the total correctly.
Sales in related dates in 2019 = SUMX ( DISTINCT ( Dates[Date] ), [Sales_2019_intermediate] )
@jdbuchanan71 Thanks for the anwser. This is a bit advanced for me. I'll get back to you in case of questions.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
108 | |
73 | |
53 | |
52 | |
44 |
User | Count |
---|---|
161 | |
110 | |
69 | |
58 | |
50 |