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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Prince87
Regular Visitor

DAX - If statement via slicer context

I need to display the records from the table which is ealrier than particular number of months , number of months will be provided by slicer selection. I created the below but it does not work -

 

Month_Filter =
var CurrentVal = SELECTEDVALUE(MOnths_Filter[Number of Months])
var Date_to_be_filtered = Dateadd('Current Inventory'[Current_Time],- CurrentVal, MONTH)


Return
SUMX('Current Inventory',IF('Current Inventory'[Date]<=Date_to_be_filtered,Sum('Current Inventory'[On Hand])))
1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @Prince87 ;

Base on my understand , you could create a flag measure and apply it into filters, as follows:

flag = IF(MONTH(MAX([Latest_ Inventory_ Date]))<=MAX('MOnths_Filter'[Number of Months]),1,0)

Then apply it into filter:

vyalanwumsft_0-1624931720889.png

The final output is shown below:

vyalanwumsft_1-1624931747519.pngvyalanwumsft_3-1624931808427.png

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

3 REPLIES 3
v-yalanwu-msft
Community Support
Community Support

Hi, @Prince87 ;

Base on my understand , you could create a flag measure and apply it into filters, as follows:

flag = IF(MONTH(MAX([Latest_ Inventory_ Date]))<=MAX('MOnths_Filter'[Number of Months]),1,0)

Then apply it into filter:

vyalanwumsft_0-1624931720889.png

The final output is shown below:

vyalanwumsft_1-1624931747519.pngvyalanwumsft_3-1624931808427.png

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

parry2k
Super User
Super User

@Prince87 you should create a calendar table, follow this blog post to create one Create a basic Date table in your data model for Time Intelligence calculations | PeryTUS IT Solutio..., and then use the date table for all the calculations and visualization.

 

Check my latest blog post Comparing Selected Client With Other Top N Clients | PeryTUS  I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



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, Sir, I already have a date table attached. This is the below scenario, from slicer user will input number of months (integer value) he needs to filter and we need to filter this table on the basis of same.

 

Prince87_0-1624775090111.png

I am trying to create the above measure but failed

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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