Home > Mobile >  Power Bi - issue with if measure
Power Bi - issue with if measure

Time:09-16

Really appreciate your help with this ! I am trying to analyze some data in power bi and this is how the data is current displayed ( just an example )

Table look like this : I am not allowed to post a pic but i hope this understand ( bold is header and the rest is the content )

1)Company 2)No of error 3)No of time to be used

A 1 3

A 4 1

B 1 2

B 1 2

C 0 1

I want the table to change into this :

1)Company 2)No of error 3)No of time to be used

A 0 1

B 0 1

C 1 1

So to explain this : so it sums what is for the same company and if the eroors are >1 then will display 0 otherwise will be 1 . For how many time is used it's the other way , if it's been used once it will 1 otherwise 0.

The purpose for this will be to calculate for a speacific period : No of errors/ no of time used *100. ( so it will count how many 1s have been in that period and do the maths )

I have used an if measure but it doesn't help as i can't count ifs ( not sure if it makes sense )

Thanks a lottt! :)

CodePudding user response:

Hello Please try this code:

You need to create "New Table" command,then paste the code:

Full DAX Code:

NewTable =
ADDCOLUMNS (
    VALUES ( YourTable[Company] ),
    "Test1", CALCULATE ( IF ( SUM ( YourTable[No of error] ) > 1, 0, 1 ) ),
    "Test2", CALCULATE ( IF ( COUNT ( YourTable[Company] ) >= 1, 1, 0 ) )
)

If we test it,

FRS

CodePudding user response:

Add company to a table visual and then add the following two measures.

Measure1 = INT( NOT( CONVERT( SUM('Table'[No of error]), BOOLEAN)) )
Measure2 = INT( CONVERT( SUM('Table'[No of time to be used]), BOOLEAN)) 

enter image description here

  • Related