Forum Discussion

forbi's avatar
forbi
Frequent Visitor
3 years ago
Solved

dax percentage calculation

I have two tables :

 

IDtypedays
1C5
2C10
3N7
4C

15

 

ProductDeadline
A10
B15

 

I want to calculate by a measure :

Divide
count rows where type = C and days <= deadline ,
count rows where type = C

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi forbi ,

    Please try below steps:

    1. below is my test table 

    Table1:

    Table2:

    2. create a measure with below dax formula

    Measure =
    VAR pt =
        SELECTEDVALUE ( Table2[Product] )
    VAR dl =
        CALCULATE ( MAX ( Table2[Deadline] ), Table2[Product] = pt )
    VAR tmp1 =
        FILTER ( ALL ( Table1 ), Table1[Type] = pt && Table1[Days] <= dl )
    VAR tmp2 =
        FILTER ( ALL ( Table1 ), Table1[Type] = pt )
    RETURN
        DIVIDE ( COUNTROWS ( tmp1 ), COUNTROWS ( tmp2 ) )
    

    3. add some visual like below

    Please refer the attached .pbix file.

     

    Best regards,
    Community Support Team_Binbin Yu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi forbi ,

    Please try below steps:

    1. below is my test table 

    Table1:

    Table2:

    2. create a measure with below dax formula

    Measure =
    VAR pt =
        SELECTEDVALUE ( Table2[Product] )
    VAR dl =
        CALCULATE ( MAX ( Table2[Deadline] ), Table2[Product] = pt )
    VAR tmp1 =
        FILTER ( ALL ( Table1 ), Table1[Type] = pt && Table1[Days] <= dl )
    VAR tmp2 =
        FILTER ( ALL ( Table1 ), Table1[Type] = pt )
    RETURN
        DIVIDE ( COUNTROWS ( tmp1 ), COUNTROWS ( tmp2 ) )
    

    3. add some visual like below

    Please refer the attached .pbix file.

     

    Best regards,
    Community Support Team_Binbin Yu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.