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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Trave97
New Member

Problem with metric calculation

Hello everyone, my level on DAX language is beginner and I’m facing a project where other stakeholders know less about it than I do.
I have this kind of table

Immagine 2022-12-01 130920.png

From the Fact table, I have to calculate a metric as the sum of the Sales (identified by the data type = "FP-Sales") from the week in which there is the first data INTAKE (data type= INTAKE) until the next 8 weeks, so for example if I find for that article X of the intake value on week 22 I have to add up the FP sales from week 22 to that of 30.

I calculated the week in which the intake value appears as:
Min week Intake = MINX( FILTER('Fact'; 'Fact'[Data type]="INTAKE");'Fact'[Week])

and I calculated also the 8 weeks (I know I can do it without creating a measure) but I was not sure of the correct output so:
End Discovery Sellout = =[Min Week Intake] + 8


So to calculate the sum of sales in this period I created this metric:
Discovery Sellout =SUMX('Fact'; IF('Fact'[Data type] = "FP-Sales" &[Min Week Intake]<='Fact'[Week] &&'Fact'[Week]=[End Discovery Sellout];'Fact'[QTY])

But it is not the desired result, because it is as if it calculated the metric on the lines where the data type = "INTAKE" is presented

I don’t understand if I’m doing something wrong (definitely! ) but I don’t know where to hit my head 😞

2 REPLIES 2
Trave97
New Member

Hi  @Greg_Deckler 
forgive me if I specified it wrong, the problem is that from this type of data (I attach sample file and screen).

Immagine 2022-12-01 174612.png

I would like to create a metric that calculates for each product the total QTY for the type of data FP-Sales, not taking all records with this condition but only those that fall within the range (week where the first intake value is presented and the next 8 weeks) in this example then I would like to have a metric that for the article A1CC2PA140C102 I have a value equal to (3+2+1=6) because the week corresponding to these values meet the condition, that is ( the week in which the first value = 17 and the next 8=25 [INTAKE DATA TYPE])

WeekData typeQTYProduct
17Intake1A1CC2PA140C102
16FP-Sales1A1CC2PA140C102
15FP-Sales7A1CC2PA140C102
22FP-Sales3A1CC2PA140C102
27FP-Sales2A1CC2PA140C102
27FP-Sales1A1CC2PA140C102
29FP-Sales6A1CC2PA140C102
29FP-Sales

5

A1CC2PA140C102

Let me know if I was clear that way,
thanks

 

Greg_Deckler
Super User
Super User

@Trave97 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.



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors