Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
I got two tables with following data. However, ExcludeRange StartDate and EndDate are measures instead of calculated columns for reason it is derived from whatif paramter then can't be calculated column.
ExcludeRange
Index | Person | StartDate | EndDate |
1 | John | 1-Dec | 2-Dec |
2 | Tom | 2-Dec | 2-Dec |
3 | John | 4-Dec | 5-Dec |
4 | Tom | 5-Dec | 5-Dec |
Sales
Date | Person | Value |
1-Dec | John | 3 |
2-Dec | John | 4 |
3-Dec | John | 5 |
4-Dec | John | 2 |
5-Dec | John | 7 |
1-Dec | Tom | 3 |
2-Dec | Tom | 4 |
3-Dec | Tom | 5 |
4-Dec | Tom | 2 |
5-Dec | Tom | 7 |
My goal is to have a measure: For each person, derive the corresponding values by Sales but exclude ExcludeRange. Result should be as following:
Date | John | Tom |
1-Dec | 3 | |
2-Dec | ||
3-Dec | 5 | 5 |
4-Dec | 2 | |
5-Dec |
I tried the following but not successful since datesbetween can't be used for multiple ranges. Any can help?
sumx('Person', calculate(sumx(sales, sales[value]), filter(sales, EXCEPT(sales[Date], DATESBETWEEN(sales[Date], 'ExcludeRange'[StartDate], 'ExcludeRange'[EndDate])))))
Solved! Go to Solution.
@amitchandakThanks your reply. Anyway, i can't make a reference to filter ExcludeRange by 'Sales'[person] and 'Sales'[date] as there is no relationship between the two tables. There are 'Person' & 'CalendarDates' tables which have relationship with these two tables. Finally i used Generate to build up a casterian between Sales and ExcludeRange and then do the filtering and the result seems work. As I am not quite familiar with DAX, it may not be simplied and optimized yet. Hope anyone has similar issue will find this help.
Exclude Sales = sumx('Person',
calculate(sum(Sales[Value]), filter(generate(Sales, ExcludeRange),
Sales[Date]>= ExcludeRange[StartDate] && Forecast[Date]<= calculate(ExcludeRange[EndDate], Allexcept(Sales, Sales[Person])) && Sales[Person] = ExcludeRange[Person]), Sales[Person] = earlier('Person'[Person])
)
)
One of the ways is to populate the index in your sales table and use it as a filter. When the index is blank
Max Index= Maxx(filter(ExcludeRange,'Sales'[person]='ExcludeRange'[person] && 'Sales'[date]>='ExcludeRange'[Start date] && 'Sales'[date]<='ExcludeRange'[end date]),ExcludeRange[index])
@amitchandakThanks your reply. Anyway, i can't make a reference to filter ExcludeRange by 'Sales'[person] and 'Sales'[date] as there is no relationship between the two tables. There are 'Person' & 'CalendarDates' tables which have relationship with these two tables. Finally i used Generate to build up a casterian between Sales and ExcludeRange and then do the filtering and the result seems work. As I am not quite familiar with DAX, it may not be simplied and optimized yet. Hope anyone has similar issue will find this help.
Exclude Sales = sumx('Person',
calculate(sum(Sales[Value]), filter(generate(Sales, ExcludeRange),
Sales[Date]>= ExcludeRange[StartDate] && Forecast[Date]<= calculate(ExcludeRange[EndDate], Allexcept(Sales, Sales[Person])) && Sales[Person] = ExcludeRange[Person]), Sales[Person] = earlier('Person'[Person])
)
)
@Anonymous in my opinion your sales tables should have person details in it, by looking at date and value, you cannot determine for which person that sales is? Am I missing something?
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
@parry2k. Thanks your reply. Yes, you are right there is person column in sales table but there is limitation of the post size so i skipped it. I have amended the example and include the person column. Kindly see.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
109 | |
99 | |
77 | |
66 | |
54 |
User | Count |
---|---|
144 | |
104 | |
102 | |
88 | |
63 |