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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Moya_Novaes
Frequent Visitor

Get the percentile of each "type" in a matrix with columns by "MonthYear"

Let this dataset be a small reproducible example.

(Update: I've also created a column MonthYear which transforms e.g. 06/01/2018 to June-2018)

DateValueType
06/01/2018100Gross Margin
06/01/2018100Gross Margin
06/01/2018100Gross Margin
06/01/2018100Gross Margin
06/01/2018100Gross Margin
06/01/2018100Gross Margin
06/01/2018100B
06/01/2018100B
06/01/2018100B
06/01/2018100C
06/01/2018100C
07/01/2018100Gross Margin
07/01/2018100Gross Margin
07/01/2018100Gross Margin
07/01/2018100B
07/01/2018100B
07/01/2018100B
07/01/2018100B
07/01/2018100B
07/01/2018100B
07/01/2018100C
07/01/2018100C
https://1drv.ms/x/s!AqdCRujnTMTHh0HpnhOVJuK3xwn5  .... (excel sharable link)

 

 

From this dataset I would like to create a Measure that gives me the Gross Margin Total, which will change by each month, just like the table bellow (in a matrix form).  Please note that I've left the calculation before the ~~ to augment the understanding


 

June - 2018

July - 2018

Gross Margin

600/600 ~~ 100%

300/300 ~~ 100%

B

300/600 ~~ 50%

600/300 ~~ 200%

C

200/600 ~~ 30%

 200/300 ~~ 66.6%



I've tried to make this by the following calculation and some variations, which failed.

 

Measure = 
VAR CurrMonthYear = FIRSTNOBLANK(TABLE[MonthYear])


RETURN 
CALCULATE( SUM( TABLE[Value]), 
FILTER(ALL(TABLE), TABLE[Type] = "Gross Margin" && TABLE[MonthYear] = CurrMonthYear))

 

1 ACCEPTED SOLUTION

Hi @Moya_Novaes ,

 

You are picking up all the table for your filter so the Dates are also being ignored in the FILTER that is being used.

 

Try to Redo your measure to:

 

%DRE =
 (
    SUM ( DRE_CONTABILIDADE[Valor] )
        / CALCULATE (
            SUM ( DRE_CONTABILIDADE[Valor] ),
            FILTER (
                ALL ( DRE_CONTABILIDADE[Nível1] ),
                DRE_CONTABILIDADE[Nível1] = "(=) RECEITA OPERACIONAL LÍQUIDA"
            )
        )
) * 100

Regards,

MFelix

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

5 REPLIES 5
MFelix
Super User
Super User

Hi @Moya_Novaes ,

 

Use the following measure to achieve the desired result:

 

% Gross Margin =
SUM ( 'Table'[Value] )
    / CALCULATE (
        SUM ( 'Table'[Value] );
        FILTER ( ALL ( 'Table'[Type] ); 'Table'[Type] = "Gross Margin" )
    )

gross_margin.png

 

Regards,

MFelix

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



I don't really know why, but my data is quite similar with the one I've created for this post and yet the denominator of the percentile gets the sum of all the database Gross Margin values, not the Gross Margin by the current MonthYear.

Screenshot from 2019-03-07 09-02-58.png

Any ideas why? I've been thiking about this even in my dreams 😛

@MFelix 

Hi @Moya_Novaes ,

 

You are picking up all the table for your filter so the Dates are also being ignored in the FILTER that is being used.

 

Try to Redo your measure to:

 

%DRE =
 (
    SUM ( DRE_CONTABILIDADE[Valor] )
        / CALCULATE (
            SUM ( DRE_CONTABILIDADE[Valor] ),
            FILTER (
                ALL ( DRE_CONTABILIDADE[Nível1] ),
                DRE_CONTABILIDADE[Nível1] = "(=) RECEITA OPERACIONAL LÍQUIDA"
            )
        )
) * 100

Regards,

MFelix

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



@MFelixAlthough I've marked as answered it isn't. 

I've copied the code you posted and I got an infinity in the denominator on rows that are not "(=) RECEITA OPERACIONAL LÍQUIDA".





Screenshot from 2019-03-07 19-08-59.png


Personaly it dosn't make sense, any ideas?

Hi @Moya_Novaes ,

 

Can you share a sample of the file?

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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