Forum Discussion

hejszyszki's avatar
hejszyszki
Frequent Visitor
5 years ago
Solved

Using countif based on 4 columns

Hi,  I'd like to perform following excel formula using dax/pq (basically in powerBI). =IF(COUNTIF(E145:L145,">90")>0,">90D",IF(COUNTIF(E145:L145,">60")>0,">60D<90D",IF(COUNTIF(E145:L145,">30")>0,...
  • selimovd's avatar
    selimovd
    5 years ago

    Hey hejszyszki ,

     

    the MAX functions can just handle 2 values. So happily I would do "MAX( myTable[W1], myTable[W2], myTable[W3], myTable[W4])", but then I receive an error because MAX can just have 2 arguments. For that reason, I split it in 2 MAX functions and get the max of these 2 MAX functions. At least with my knowledge, that's the easiest way in your case.

     

    For the blank values you can sure return nothing:

    Countif =
    VAR vMaxRowValue =
        MAX(
            MAX(
                myTable[W1],
                myTable[W2]
            ),
            MAX(
                myTable[W3],
                myTable[W4]
            )
        )
    RETURN
        SWITCH(
            TRUE(),
            vMaxRowValue = BLANK() || vMaxRowValue = "", BLANK(),
            vMaxRowValue > 90, ">90D",
            vMaxRowValue > 60, ">60D<90D",
            vMaxRowValue > 30, ">30D<60D",
            vMaxRowValue > 14, ">14D<30D",
            vMaxRowValue < 14, "<14D"
        )

     

    If you need any help please let me know.
    If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
     
    Best regards
    Denis