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
WLFRD
Helper III
Helper III

Calculate ratio between E and B in the same column

Hello,

 

I would like to calculate the ratio between E and B in the same column.

 

DateTypeCount_Of_Type
9/20/2021 0:00B35
9/20/2021 0:00D24
9/20/2021 0:00E1775
9/20/2021 0:00S1710
9/21/2021 0:00B45
9/21/2021 0:00D9
9/21/2021 0:00E2246
9/21/2021 0:00S937
9/22/2021 0:00B55
9/22/2021 0:00D9
9/22/2021 0:00E2020
9/22/2021 0:00S1495
9/23/2021 0:00B47
9/23/2021 0:00D9
9/23/2021 0:00E1927
9/23/2021 0:00S885
9/24/2021 0:00B28
9/24/2021 0:00D6
9/24/2021 0:00E1735
9/24/2021 0:00S981

 

So for each day, a ratio is desired. 

Can someone help me out with this?

 

Thanks in advance.

 

11 REPLIES 11
goncalogeraldes
Super User
Super User

Hello there @WLFRD !

 

ratio =
var _e = CALCULATE(COUNT(Table[Type]), FILTER(Table, Table[Type] = "E"))
var _b = CALCULATE(COUNT(Table[Type]), FILTER(Table, Table[Type] = "B"))

return
DIVIDE( _e, _b)

Hope this answer solves your problem!
If you need any additional help please @ me in your reply.
If my reply provided you with a solution, please consider marking it as a solution ✔️ or giving it a kudoe 👍
Thanks!

You can also check out my LinkedIn!

Best regards,
Gonçalo Geraldes

@goncalogeraldes 

Thanks for your reply! This is the return (after skipping out the S and D):

 

DateTypeCount_Of_typeratio
9/20/2021 0:00B350.675583141
9/20/2021 0:00E177534.26171645
9/21/2021 0:00B450.868606896
9/21/2021 0:00E224643.3531353
9/22/2021 0:00B551.061630651
9/22/2021 0:00E202038.99079844
9/23/2021 0:00B470.907211647
9/23/2021 0:00E192737.19567753
9/24/2021 0:00B280.540466513
9/24/2021 0:00E173533.48962144

 

I was expecting:

 

DateTypeCount_Of_TypeRatio
9/20/2021 0:00B35 
9/20/2021 0:00E17750.0197
9/21/2021 0:00B45 
9/21/2021 0:00E22460.0200
9/22/2021 0:00B55 
9/22/2021 0:00E20200.0272
9/23/2021 0:00B47 
9/23/2021 0:00E19270.0244
9/24/2021 0:00B28 
9/24/2021 0:00E17350.0161

 

35/1775 = 0.0197

 

So I don't know what goes wrong. 

 

Best regards.

@WLFRD , I think that what you want is this then:

ratio =
var _e = CALCULATE(COUNT(Table[Type]), FILTER(Table, Table[Type] = "E"))
var _b = CALCULATE(COUNT(Table[Type]), FILTER(Table, Table[Type] = "B"))
var _selected = SELECTEDVALUE(Table[Type])

return
IF( _selected = "E",
DIVIDE( _b, _e))

Hope this answer solves your problem!
If you need any additional help please @ me in your reply.
If my reply provided you with a solution, please consider marking it as a solution ✔️ or giving it a kudoe 👍
Thanks!

You can also check out my LinkedIn!

Best regards,
Gonçalo Geraldes

@goncalogeraldes 

For some reason the added 'selected' statement IF( _selected = "E") is not recognized bij Power BI. 

 

Would there another solution to calculate the ratio between B and E per day?

 

Thanks in advance.

@WLFRD what is the error message you receive? 

@goncalogeraldes 

I would like to have the ratio per day. Now it seems it calculates the ratio for the entire column.

Hi @WLFRD 

 

You want a measure or a column to get the ratio? If you want a measure, you need to put date column and ratio measure into the same visual. Then the date column will provide a date filter to the ratio measure.  

 

Or you could try this measure:

Ratio = 
var _b = CALCULATE(SUM('Table'[Count_Of_Type]),ALLEXCEPT('Table','Table'[Date]),'Table'[Type]="B")
var _e = CALCULATE(SUM('Table'[Count_Of_Type]),ALLEXCEPT('Table','Table'[Date]),'Table'[Type]="E")
var _selected = SELECTEDVALUE('Table'[Type])
return
IF( _selected = "E",DIVIDE( _b, _e))

 

Best Regards,
Community Support Team _ Jing

If this post helps, please Accept it as Solution to help other members find it.

@v-jingzhang 

Thanks for your reply! This seems a way to calculate the ratio. I just have a small adition to this. Suppose we don't have the count column and this is the data we have:

 

DateType
9/20/2021B
9/20/2021B
9/20/2021B
9/20/2021E
9/20/2021E
9/20/2021E
9/20/2021S
9/20/2021S
9/20/2021E
9/20/2021E
9/20/2021E
9/20/2021E
9/20/2021E
9/20/2021S
9/20/2021S
9/20/2021E
9/20/2021E
9/20/2021E
9/20/2021E
9/20/2021E
9/20/2021E
9/20/2021B
9/20/2021B
9/20/2021B
9/20/2021B
9/20/2021S
9/20/2021S
9/21/2021E
9/21/2021E
9/21/2021E
9/21/2021E
9/21/2021B
9/21/2021B
9/21/2021B
9/21/2021E
9/21/2021E
9/21/2021S
9/21/2021S
9/21/2021S
9/21/2021S
9/22/2021E
9/22/2021E
9/22/2021E
9/22/2021E
9/22/2021B
9/22/2021B
9/22/2021B
9/22/2021E
9/22/2021E
9/22/2021S
9/22/2021S
9/22/2021S
9/22/2021E
9/22/2021E
9/22/2021E
9/22/2021E
9/22/2021B
9/22/2021B
9/23/2021E
9/23/2021E
9/23/2021E
9/23/2021E
9/23/2021B
9/23/2021B
9/23/2021S
9/23/2021S
9/23/2021S
9/23/2021E
9/23/2021E
9/23/2021E
9/23/2021E
9/23/2021E
9/23/2021B
9/23/2021B
9/23/2021S
9/23/2021S
9/23/2021B

 

The B and E have to be counted per day and based on this count, the ratio has to be calculated.

How do you add this count to the DAX calculation?

 

Thanks in advance.

 

your help is much appreciated

Hi @WLFRD 

 

It is similar. Create two measures.

 
Count of Type = COUNT('Table'[Type])

 

Ratio =
var _b = CALCULATE([Count of Type],ALLEXCEPT('Table','Table'[Date]),'Table'[Type]="B")
var _e = CALCULATE([Count of Type],ALLEXCEPT('Table','Table'[Date]),'Table'[Type]="E")
var _selected = SELECTEDVALUE('Table'[Type])
return
IF( _selected = "E",DIVIDE( _b, _e))
 
BR,
Jing

@v-jingzhang 

Thanks for your help! This worked for me but I do have a question.... suppose I don't have the Count_of_type colomn so I have to count per day the "B" and "E" Type, what will then be the calculation?

 

DateType
9/20/2021B
9/20/2021B
9/20/2021B
9/20/2021E
9/20/2021E
9/20/2021E
9/20/2021S
9/20/2021S
9/20/2021E
9/20/2021E
9/20/2021E
9/20/2021E
9/20/2021E
9/20/2021S
9/20/2021S
9/20/2021E
9/20/2021E
9/20/2021E
9/20/2021E
9/20/2021E
9/20/2021E
9/20/2021B
9/20/2021B
9/20/2021B
9/20/2021B
9/20/2021S
9/20/2021S
9/21/2021E
9/21/2021E
9/21/2021E
9/21/2021E
9/21/2021B
9/21/2021B
9/21/2021B
9/21/2021E
9/21/2021E
9/21/2021S
9/21/2021S
9/21/2021S
9/21/2021S
9/22/2021E
9/22/2021E
9/22/2021E
9/22/2021E
9/22/2021B
9/22/2021B
9/22/2021B
9/22/2021E
9/22/2021E
9/22/2021S
9/22/2021S
9/22/2021S
9/22/2021E
9/22/2021E
9/22/2021E
9/22/2021E
9/22/2021B
9/22/2021B
9/23/2021E
9/23/2021E
9/23/2021E
9/23/2021E
9/23/2021B
9/23/2021B
9/23/2021S
9/23/2021S
9/23/2021S
9/23/2021E
9/23/2021E
9/23/2021E
9/23/2021E
9/23/2021E
9/23/2021B
9/23/2021B
9/23/2021S
9/23/2021S
9/23/2021B

 

 

Thanks for your help!

 

Much appreciated!

 

 

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors