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
ekelly
New Member

Need help with Dax If statement including a measure

We are trying to create a green/red stacked bar report relating our inventory and sales.  Sales is our starting point and the green/red status is a relationship of inventory to sales.  For example, if we have 1,000 units in sales and 400 units in stock, 400 would be green (as these are in stock) and 600 would be red (as we need more units to complete the sale).  This we have working in Power BI.  It is the scenario for when we have more stock than sales that we cannot cap the green at our sale.  For example, if we have 1,000 units in sales and 2,000 units in stock, we want green to be 1,000 (because we don't care we have excess) and red would be 0 (as nothing needs to be produced to meet the sale).

 

Our issue is that our sales data is a direct metric from our data source, but the inventory is a new measure using the below formula.  This is due to our data having the inventory for an item stated multiple times (when it is a unique instance to that item) and this metric should not be summed.   

=SUMX (DISTINCT([Item Number]), FIRSTNONBLANK ([On Hand]), 0)

 

What we are trying to create two new measures to drive our green and red visual. 

Green would be....If Inventory >=Sales then bring back Sales metric

Red would be... If Inventory <Sales then subtract Inv from Sales

 

We are having issues with Dax since our Inventory is already a measure and our knowledge of Dax is minimal. 

 

  

1 ACCEPTED SOLUTION

Hi @ekelly

Create two measures

available = IF(MAX([Sales])<[Inventory in Stock],MAX([Sales]),[Inventory in Stock])
need = IF(MAX([Sales])>[Inventory in Stock],MAX([Sales])-[Inventory in Stock],0)

6.png

7.png

 

Best Regards

Maggie 

View solution in original post

4 REPLIES 4
alexei7
Continued Contributor
Continued Contributor

Hi @ekelly,

 

It'd be helpful to understand what you're trying to achieve if you could share some sample data (or even better, a pbix model), obviously removing any sensitive/confidential data.

 

Thanks

Alex

Here would be a sample of the chart we are looking to achieve.  Green and Red in the chart would be new measures and then we would create the stacked bar visual with these new measures.

 Chart.JPGStacked Bar.JPG

The complexity is that inventory in stock is already a new measure using the below formula from our data source.  I cannot share the actual pbix, as it does contain confidential information.

 

=SUMX (DISTINCT([Item Number]), FIRSTNONBLANK ([On Hand]), 0)

Hi @ekelly

Create two measures

available = IF(MAX([Sales])<[Inventory in Stock],MAX([Sales]),[Inventory in Stock])
need = IF(MAX([Sales])>[Inventory in Stock],MAX([Sales])-[Inventory in Stock],0)

6.png

7.png

 

Best Regards

Maggie 

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.