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
reboundgt9
Frequent Visitor

Variable in a measure to return current month even if there is no data

I am in the process of creating a report that is refreshed on a monthly basis, however, I have not been able to create a DAX formula that is sufficient for my needs and instead I have been manually updating the formula on a monthly basis which is certainly not ideal. FYI – I am self-taught and very new to Power BI.

 

I have a data pull that will return a list of clients and the products they purchased that incurred sales over $10k in a given month. Clients without a purchase, or those that did not exceed the $10k threshold for any given product, are excluded from the data file.

 

I have my measures set up within a matrix with two columns. The first column returns the unique number of products that exceeded the sales threshold in the most recent month. The second column returns the percentage of sales associated with the products over the $10k threshold as a percentage of the current months total sales. For example, over the course of the past month Client A purchased 5 different products with total sales of $100k. However, only 2 of those products total sales exceeded the $10k threshold, Product 1 was $45k and Product 2 was $40k. The other 3 products made up the final $15k in sales. The first column would then return “2” and the second column would return “85%.” The measures are working but I must manually update the date each month instead of this being dynamic.

 

My problem is that if I use Max Date, it will return values for the most recent month in which the client had sales eclipse the $10k threshold for a product instead of the most recent month. For example, if Client B last had a product purchase over $10k back in June 2021, the matrix will show that months data instead of excluding them entirely. I would like to exclude those client from the matrix that do not meet the metric for the most recent month.  

 

Below is my current measure for distinct count of products. As you can see, the date is hard-coded.

Sales in current month over $10k = CALCULATE(SUM('Client Sales over $10k'[Product Distinct Count]),FILTER('Client Sales over $10k','Client Sales over $10k'[Paid YYYYMM]=(202110)))

 

Any suggestions are much appreciated!

1 ACCEPTED SOLUTION
V-lianl-msft
Community Support
Community Support

Hi ,

 

If you just want to exclude others from the matrix, you can create a measure as a visual level filter:

 

 

Measure_filter = 
var max_date = CALCULATE(MAX('Table'[Paid YYYYMM]),ALL('Table'))
return IF(max_date=MAX('Table'[Paid YYYYMM]),1,0)

 

 

Vlianlmsft_0-1637908228195.png

 

 

Best Regards,
Liang
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

4 REPLIES 4
ArquimedesP
Helper I
Helper I

Hi! Could you solved this? If you did, could you please share the answer? I have the same problem. The formula bring current values if it has, but, when it doesn't bring lastest avaliable month data. I had tried with DATESMTD, DATEADD, IF and even variables. 

V-lianl-msft
Community Support
Community Support

Hi ,

 

If you just want to exclude others from the matrix, you can create a measure as a visual level filter:

 

 

Measure_filter = 
var max_date = CALCULATE(MAX('Table'[Paid YYYYMM]),ALL('Table'))
return IF(max_date=MAX('Table'[Paid YYYYMM]),1,0)

 

 

Vlianlmsft_0-1637908228195.png

 

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

Greg_Deckler
Super User
Super User

@reboundgt9 Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Please let me know if this is helpful. Below is some made up sample data.

 

Data below shows 3 clients and sales by date, product ID, and Sales total. I would like to show only Client B as 2 since the most recent Paid YYYYMM is 202110. I would like to exclude Client A and Client C as they did not have sales in the most recent time period. Currently, I am only able to return Client B as expected if I manually input the date within the measure itself.

 

Client NamePaid YYYYMMProduct IDSales Total
Client A20210700002013895922,000.
Client B20211000001563022815,000.
Client B20211000001052340110,500.
Client B20210800001472039250,000.
Client B20210700001591812711,400.
Client C20210600002016098419,700

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.