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

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.

Reply
RGregory
Regular Visitor

Filter a Fact Table to Exclude Item Exceptions By Date Range

I have a list of transactions by Date and Item (multiple dates and items) and now I need to exclude certain items based on the date ranges in this second table.
(items can appear multiple times - item A is offline between 1/1/2023 and 1/4/2023, but also item A is offline 2/15/2023-2/16/2023)

If the transaction date, for that item appears in one of these entries, it needs to be flagged 1, otherwise 0.

...I did set up an inactive many to many relationship on item ID, so I could call upon item IDs to match them, but filtering between the date fields is tricky.

... also, i do have a date table in this model

1 ACCEPTED SOLUTION
Sahir_Maharaj
Super User
Super User

Hello @RGregory,

 

1. Create a separate table for the exclusion dates with columns for Item, Start Date, and End Date.

 

2. Create a measure that calculates whether a transaction falls within any of the exclusion date ranges for the item.

 

Transaction Flag = 
VAR ItemID = MAX('Transactions'[Item ID])
VAR TransactionDate = MAX('Transactions'[Transaction Date])
VAR Exclusions = FILTER(ExclusionDates, ExclusionDates[Item] = ItemID && TransactionDate >= ExclusionDates[Start Date] && TransactionDate <= ExclusionDates[End Date])
RETURN IF(COUNTROWS(Exclusions) > 0, 1, 0)

 

 

3. Add the Transaction Flag measure to your visualizations to see which transactions are flagged based on the exclusion dates.

4. You can also use the measure to filter your data by creating a filter that includes only transactions with a flag of 0 (i.e., transactions that are not excluded).

 

Let me know if you might require further assistance.


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution?
➤ Lets connect on LinkedIn: Join my network of 13K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

View solution in original post

2 REPLIES 2
RGregory
Regular Visitor

Very helpful! Thank you.

I was trying to create this as a calculated column, and doing it the way prescribed above does not work on column.

 

Instead, I used the steps above to create the Flag as a measure, then used some DAX on column to tie them together.

 

Thanks!

Sahir_Maharaj
Super User
Super User

Hello @RGregory,

 

1. Create a separate table for the exclusion dates with columns for Item, Start Date, and End Date.

 

2. Create a measure that calculates whether a transaction falls within any of the exclusion date ranges for the item.

 

Transaction Flag = 
VAR ItemID = MAX('Transactions'[Item ID])
VAR TransactionDate = MAX('Transactions'[Transaction Date])
VAR Exclusions = FILTER(ExclusionDates, ExclusionDates[Item] = ItemID && TransactionDate >= ExclusionDates[Start Date] && TransactionDate <= ExclusionDates[End Date])
RETURN IF(COUNTROWS(Exclusions) > 0, 1, 0)

 

 

3. Add the Transaction Flag measure to your visualizations to see which transactions are flagged based on the exclusion dates.

4. You can also use the measure to filter your data by creating a filter that includes only transactions with a flag of 0 (i.e., transactions that are not excluded).

 

Let me know if you might require further assistance.


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution?
➤ Lets connect on LinkedIn: Join my network of 13K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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