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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Silvie
Helper I
Helper I

MAT calculation wrong

Hi, 

 

I posted this on Saturday as a reply on an existing topic, but didn't get any answer yet. That's why I'm creating a new message. 

I'm new at calculating rather complex formulas. I need to calculate the MAT based on a measure. 

Table with data see below including what we expect the MAT result should look like. 

DateOOP - ABOOP - with EcoscoreExpected MAT result
01/02/202262006571,96153290854,87 
01/03/202275885416,73203187723,93 
01/04/202281008926,08246855401,59 
01/05/202280554289,31242783685,49 
01/06/202280889841,36244188668,79 
01/07/202283651207,72246026973,7 
01/08/202290373368,73258385872,05 
01/09/202288898086,38252980248,4 
01/10/2022100886308,19355064447,87 
01/11/2022114580142,92368026113,14 
01/12/2022134022067,66446482406 
01/01/2023120197150,76348696194,3733,06% = sum of ' OOP - AB' from 02/2022 till 01/2023  divided by the sum of 'OOP - with Ecoscore' from 02/2022 till 01/2023
01/02/2023116118961,65335621916,2632.89% =  sum of ' OOP - AB' from 03/2022 till 02/ 2023 divided by the sum of 'OOP - with Ecoscore' from 03/2022 till 02/ 2023
01/03/2023138040772,3402175919,5932.80%
01/04/2023138203247,47386740063,9133.09%
01/05/2023121148045,18302451488,7533.62%
01/06/2023146359040,74380171755,0134,11%
01/07/2023136880971,51356216795,6934.48%
01/08/2023140059604,92358827668,5634,83%
01/09/2023141468248,64364874261,4835,14%
01/10/2023142689405,06366071051,7736.00%
01/11/2023138292652,57358040963,3236.62%
01/12/2023159139285,21440116959,0837.24%

I used the same logic as mentioned in this solution, using 'SAMEPERIODLASTYEAR' but I'm getting other results. 

 

This is the formula I used to calculate the MAT: 

% Ecoscore MAT Y-1 = calculate(
Ecoscore[% Ecoscore met A+B],
SAMEPERIODLASTYEAR(DATESINPERIOD(Ecoscore[Date],max(Ecoscore[Date]),-12,month))
)

The formula for the % Ecoscore met A+B measure looks like this (and is correct) 

=Calculate(

Sum(Ecoscore[OOP]),

Filter('Ecoscore','Ecoscore'[Ecoscore] In {"A","B"}))/

Calculate(Sum('Ecoscore'[OOP]),Filter('Ecoscore','Ecoscore'[Ecoscore] In {"A","B","C","D","E"})

)

Could someone help me out please? What am I doing wrong?

Kind regards,

Silvie

1 ACCEPTED SOLUTION

Your data model looks reasonable. Personally I would merge the Periode Type data into the Calendar table (like you did in the Periode Dimensies OLD.

 

You must use &&  , not  ||  

 

You must use the date from the calendar table, not from the fact table

 

% Nutriscore MAT = 
var d = max('Calendar'[Date])
var a = filter(ALLSELECTED(Nutriscore),Nutriscore[Date]<=d && Nutriscore[Date]>EDATE(d,-12))
return if (countrows(a)=12,divide(sumx(a,Nutriscore[OOP Nutriscore A-B]),sumx(a,Nutriscore[OOP Nutriscore]),0))

View solution in original post

7 REPLIES 7
lbendlin
Super User
Super User

SAMEPERIODLASTYEAR has a different purpose.

lbendlin_0-1706218877734.png

if you want to suppress incomplete windows, use

lbendlin_1-1706218929822.png

 

 

 

I tried to visualize the results in a line chart or table, but I'm not getting any results. 

When I try to select the organization (Org) or organization type (Org Type) it also doesn't work. I should be able to select between GROUP, VERTICAL or OU as org type. 

I've put my pbix file on my Onedrive: A016 Ecoscore - A017 Nutriscore.pbix

Maybe someone can find out what I'm doing wrong? Or should I start all over? 

Your data model looks reasonable. Personally I would merge the Periode Type data into the Calendar table (like you did in the Periode Dimensies OLD.

 

You must use &&  , not  ||  

 

You must use the date from the calendar table, not from the fact table

 

% Nutriscore MAT = 
var d = max('Calendar'[Date])
var a = filter(ALLSELECTED(Nutriscore),Nutriscore[Date]<=d && Nutriscore[Date]>EDATE(d,-12))
return if (countrows(a)=12,divide(sumx(a,Nutriscore[OOP Nutriscore A-B]),sumx(a,Nutriscore[OOP Nutriscore]),0))

Hi Ibendlin, 

 

The formula seems to work, I'm not getting any errors, but when I want to create a table or line chart, it is blank. 

Silvie_1-1706259514949.png

 

This is how my data model looks like: 

Silvie_0-1706259488040.png

There is a relationship between the 'Ecoscore' table and 'Periode Dimensies' table through the field 'Period' and a relationship between the 'Ecoscore' table and 'Organisatie Dimensies' table through the (Org)Key field. 

The 'Ecoscore' table is linked to the 'Calendar' table through 'Date'.

I tried removing the relationships with the Nutriscore tables and the one with the Period field but it doesn't seem to work. 

Do you have any suggestions what I can do to make this work?

 

I also tried the formula below to avoid the "&&" but this also doesn't work. 

 

Silvie_0-1706257053247.png

 

Hi Ibendlin,

 

Many thx for looking into my issue. The result looks very good!

The only issue I'm encountering is that PBI doens't find my Date column after writing "&&" in the the var a line. I can only choose between my created measures. 

Is there another way to solve this? 

My bad, I forgot a bracket in the formula.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.