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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Jorrafer25
Frequent Visitor

Filter two tables based on dates and sum the result

Hello community!

I have a problem summing the result of two tables. The first table has the sold quantities. The second table has the forecasted quantities. Both tables are linked to a calendar table (not represented). The third table has cut-off dates for both products.

 

Exported:

ProductDateQuantity
A1/1/202210
A2/1/202210
A3/1/202210
B1/1/20225
B2/1/20225
B3/1/20225

 

Forecast

ProductDateQuantity
A1/1/202220
A2/1/202220
A3/1/202220
A4/1/202220
B1/1/202215
B2/1/202215
B3/1/202215
B4/1/202215

 

Cut Off Dates

ProductCutOffDate
A2/1/2022
B3/1/2022

 

The first goal is to filter both tables with the cut off date, getting from the first table and the product A & B:

ProductDateQuantity
A1/1/202210
A2/1/202210
B1/1/20225
B2/1/20225
B3/1/20225

 

Those dates are <=2/1/2022 for product A (The cut off date for product A) and <=3/1/2022 for product B (The cut off date for product B).

 

After that I need the same for table 2, but considering the dates after the cut off date:

 

ProductDateQuantity
A3/1/202220
A4/1/202220
B4/1/202215

 

Next, I need to mix both tables to obtain:

 

ProductDateQuantity
A1/1/202210
A2/1/202210
A3/1/202220
A4/1/202220
B1/1/20225
B2/1/20225
B3/1/20225
B4/1/202215

 

Finally, my goal is to have the following result:

 

DateQuantity
1/1/202215
2/1/202215
3/1/202225
4/1/202235

 

I tried to do it using max for the dates, but I can't keep the Product context filter, causing that my table is only filtered by my maximum cut off date (3/1/2022)

 

Thanks in advance!

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

CNENFRNL_0-1667262592921.png

CNENFRNL_1-1667262807009.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

2 REPLIES 2
CNENFRNL
Community Champion
Community Champion

CNENFRNL_0-1667262592921.png

CNENFRNL_1-1667262807009.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

daXtreme
Solution Sage
Solution Sage

Hi @Jorrafer25 

 

Well, this looks to me like a job for Power Query, not DAX. If you do it in PQ, you should be good to go with your reports without doing any strange acrobatics in DAX. Things will get soooooo much easier and faster...

 

If I get a bit of time, I'll try to write/generate the M code for this in Power Query.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors