Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Hello all, I have problem building a DAX measure equivalent to Sumifs in excel. To start with, I know it is to use CALCULATE(SUM(),filter 1, filter 2) but I don't know how to input the filter when it is based on another column.
Below is a simplified version of my data - monthly revenue records from a list of clients from 2021-2024. As some are new clients and some are churned, not all the clients have records in the whole period.
Client | Revenue Month | Gross Revenue |
abc | 01 September 2023 | 2049 |
abc | 01 January 2024 | 29 |
qwe | 01 December 2023 | 2 |
qwe | 01 October 2023 | 810 |
qwe | 01 September 2023 | 7665 |
asd | 01 December 2021 | 576 |
asd | 01 November 2022 | 470 |
asd | 01 October 2022 | 859 |
asd | 01 September 2022 | 1371 |
bnm | 01 August 2022 | 672 |
yui | 01 July 2022 | 43 |
yui | 01 September 2023 | 200 |
yui | 01 January 2024 | 1161 |
The SUMIFS I would like to have is to sum up the Revenue amount with below 2 criteria.
1) Current 24 months of revenue
2) Only from clients that have generated revenue from the same month last year
The final output will be a bar chart of Revenue against Month like below:
In such case, the Jan 2024 bar will show the sum of last 24 months revenue generated by only the clients that generated revenue in Jan 2023; and the Jul 2023 bar will show the sum of last 24 months revenue generated by only the clients that have generated revenue in Jul 2022.
The underlying data will be updated once a month when new month comes in. I managed to fulfill the first criteria with below measure but don't know how to input the second criteria, becuase I am not filtering the date directly but the client list based ont he date. Please could anyone help?
Thanks a lot!!!
Solved! Go to Solution.
change
Cumul =
var d = max('Calendar'[Date])
var c = values('Table'[Client])
var pc = SELECTCOLUMNS(CALCULATETABLE(VALUES('Table'[Client]),'Calendar'[Date]=EDATE(d,-12)),"Client",[Client])
var yoyc = intersect(c,pc)
return CALCULATE(sum('Table'[Gross Revenue]),'Table'[Client] in yoyc,'Calendar'[Date] <=d,'Calendar'[Date]>EDATE(d,-24))
to
Cumul =
var d = max('Calendar'[Date])
var pc = SELECTCOLUMNS(CALCULATETABLE(VALUES('Table'[Client]),'Calendar'[Date]=EDATE(d,-12)),"Client",[Client])
return CALCULATE(sum('Table'[Gross Revenue]),'Table'[Client] in pc,'Calendar'[Date] <=d,'Calendar'[Date]>EDATE(d,-24))
Your sample data is insufficient.
Please provide sample data that fully covers your issue.
Please show the expected outcome based on the sample data you provided.
Hello, my data has more than 50k rows to cover all the years so the above data is just a simplified version to show how it looks like. How can I provide this data here?
The bar chart I posted in the question is the expected outcome. Please let me know what else I should provide, thank you.
none of your sample data matches your criteria. Please provide sample data that fully covers your issue.
Sorry for that. I have created another sample data as below with 4 clients and their revenue spread across 2021-2024 (not all the months have revenue from all 4 clients). Would that be fine? Thanks a lot!!
Client | Revenue Month | Gross Revenue |
abc | 01 January 2021 | 9293 |
abc | 01 February 2021 | 8766 |
abc | 01 March 2021 | 4686 |
abc | 01 April 2021 | 4359 |
abc | 01 May 2021 | 7045 |
abc | 01 June 2021 | 2887 |
abc | 01 July 2021 | 1980 |
abc | 01 August 2021 | 7095 |
abc | 01 September 2021 | 1090 |
abc | 01 October 2021 | 4097 |
abc | 01 November 2021 | 1025 |
abc | 01 December 2021 | 5564 |
abc | 01 January 2022 | 9342 |
abc | 01 February 2022 | 7857 |
abc | 01 March 2022 | 4326 |
abc | 01 April 2022 | 1661 |
abc | 01 May 2022 | 568 |
abc | 01 June 2022 | 7381 |
abc | 01 July 2022 | 1044 |
abc | 01 August 2022 | 9313 |
abc | 01 September 2022 | 3289 |
abc | 01 October 2022 | 2524 |
abc | 01 November 2022 | 8067 |
abc | 01 December 2022 | 5067 |
abc | 01 January 2023 | 653 |
abc | 01 February 2023 | 2506 |
abc | 01 March 2023 | 7750 |
abc | 01 April 2023 | 6728 |
abc | 01 May 2023 | 1409 |
abc | 01 June 2023 | 1119 |
abc | 01 July 2023 | 7218 |
abc | 01 August 2023 | 1080 |
abc | 01 September 2023 | 7984 |
abc | 01 October 2023 | 4474 |
abc | 01 November 2023 | 8752 |
abc | 01 December 2023 | 7937 |
abc | 01 January 2024 | 6201 |
abc | 01 February 2024 | 8056 |
abc | 01 March 2024 | 8611 |
abc | 01 April 2024 | 1857 |
abc | 01 May 2024 | 7792 |
abc | 01 June 2024 | 9599 |
abc | 01 July 2024 | 844 |
abc | 01 August 2024 | 7523 |
abc | 01 September 2024 | 2393 |
abc | 01 October 2024 | 3873 |
abc | 01 November 2024 | 8115 |
abc | 01 December 2024 | 3921 |
def | 01 January 2023 | 3446 |
def | 01 February 2023 | 688 |
def | 01 March 2023 | 2387 |
def | 01 April 2023 | 7429 |
def | 01 May 2023 | 8737 |
def | 01 June 2023 | 6088 |
def | 01 July 2023 | 9206 |
def | 01 August 2023 | 5973 |
def | 01 September 2023 | 4737 |
def | 01 October 2023 | 4722 |
def | 01 November 2023 | 3005 |
def | 01 December 2023 | 5171 |
ghi | 01 November 2022 | 2255 |
ghi | 01 December 2022 | 2052 |
ghi | 01 January 2023 | 3458 |
ghi | 01 February 2023 | 9694 |
ghi | 01 March 2023 | 5958 |
ghi | 01 April 2023 | 2755 |
ghi | 01 May 2023 | 2830 |
ghi | 01 June 2023 | 6555 |
ghi | 01 July 2023 | 1280 |
ghi | 01 August 2023 | 2806 |
ghi | 01 September 2023 | 6985 |
ghi | 01 October 2023 | 5588 |
ghi | 01 November 2023 | 4413 |
ghi | 01 December 2023 | 9755 |
ghi | 01 January 2024 | 3674 |
ghi | 01 February 2024 | 4631 |
ghi | 01 March 2024 | 8251 |
ghi | 01 April 2024 | 1665 |
ghi | 01 May 2024 | 3965 |
ghi | 01 June 2024 | 5606 |
ghi | 01 July 2024 | 5114 |
ghi | 01 August 2024 | 3951 |
ghi | 01 September 2024 | 4773 |
ghi | 01 October 2024 | 9556 |
ghi | 01 November 2024 | 3399 |
ghi | 01 December 2024 | 7994 |
jkl | 01 April 2023 | 6032 |
jkl | 01 May 2023 | 9406 |
jkl | 01 June 2023 | 3464 |
jkl | 01 July 2023 | 3598 |
jkl | 01 August 2023 | 4894 |
jkl | 01 September 2023 | 5268 |
jkl | 01 October 2023 | 9846 |
jkl | 01 November 2023 | 3213 |
jkl | 01 December 2023 | 5506 |
jkl | 01 January 2024 | 6109 |
jkl | 01 February 2024 | 2709 |
jkl | 01 March 2024 | 4500 |
jkl | 01 April 2024 | 4838 |
jkl | 01 May 2024 | 1039 |
jkl | 01 June 2024 | 2135 |
jkl | 01 July 2024 | 3001 |
jkl | 01 August 2024 | 4263 |
jkl | 01 September 2024 | 8892 |
jkl | 01 October 2024 | 2496 |
jkl | 01 November 2024 | 6810 |
jkl | 01 December 2024 | 8066 |
Cumul =
var d = max('Calendar'[Date])
var c = values('Table'[Client])
var pc = SELECTCOLUMNS(CALCULATETABLE(VALUES('Table'[Client]),'Calendar'[Date]=EDATE(d,-12)),"Client",[Client])
var yoyc = intersect(c,pc)
return CALCULATE(sum('Table'[Gross Revenue]),'Table'[Client] in yoyc,'Calendar'[Date] <=d,'Calendar'[Date]>EDATE(d,-24))
Thanks very much for your reply with solution but it is not correct unfortunately.
For example, the bar of Dec 2024 should look at the last 24 months revenue generated by the clients who contribute to revenue in Dec 2023. As all 4 clients generate revenue in Dec 2023, that bar should look at the revenue from all 4 clients from Jan 2022 to Dec 2024. The total sum of the Dec 2024 bar should be $418,725. Also, the Cuml chart is missing out Client def (dark blue color) but it should be included in some bars.
Please could you help to take a look again? Thanks so much really!!
change
Cumul =
var d = max('Calendar'[Date])
var c = values('Table'[Client])
var pc = SELECTCOLUMNS(CALCULATETABLE(VALUES('Table'[Client]),'Calendar'[Date]=EDATE(d,-12)),"Client",[Client])
var yoyc = intersect(c,pc)
return CALCULATE(sum('Table'[Gross Revenue]),'Table'[Client] in yoyc,'Calendar'[Date] <=d,'Calendar'[Date]>EDATE(d,-24))
to
Cumul =
var d = max('Calendar'[Date])
var pc = SELECTCOLUMNS(CALCULATETABLE(VALUES('Table'[Client]),'Calendar'[Date]=EDATE(d,-12)),"Client",[Client])
return CALCULATE(sum('Table'[Gross Revenue]),'Table'[Client] in pc,'Calendar'[Date] <=d,'Calendar'[Date]>EDATE(d,-24))
It works!! Thank you so much!! I have marked this as the solution already 🙂
User | Count |
---|---|
58 | |
21 | |
18 | |
16 | |
13 |
User | Count |
---|---|
85 | |
54 | |
45 | |
39 | |
21 |