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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

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!:
Mastering Power BI 2nd Edition

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
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.