Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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.
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
72 | |
67 | |
51 | |
38 | |
26 |
User | Count |
---|---|
88 | |
52 | |
45 | |
39 | |
38 |