Forum Discussion

MightyRabbit's avatar
MightyRabbit
Frequent Visitor
3 years ago
Solved

How to count the measure

Dear all, 

I have a table name "Sheet1" like this:

SeriesNo
F881234
F881235
F881236
F881237
F881240
A253456
A253457
A253459
A253460

 

I've used the following query to figure out, which number is missing in the sequency:

Missing_No =
VAR cur_serrie =
    SELECTEDVALUE ( 'Sheet1'[Series] )
VAR tmp =
    FILTER ( ALL ( 'Sheet1'), 'Sheet1'[Series]= cur_serrie )
VAR tmp1 =
    CALCULATETABLE ( VALUES ( 'Sheet1'[No]), tmp )
VAR max_no =
    MAXX ( tmp, [No] )
VAR min_no =
    MINX ( tmp, [No])
VAR tmp2 =
    GENERATESERIES ( COALESCE ( min_no, 0 ), COALESCE ( max_no, 0 ), 1 )
VAR tmp3 =
    EXCEPT ( tmp2, tmp1 )
RETURN
    CONCATENATEX ( tmp3, [Value], "," )


It returns to what I want to see, when I show it with table:

My question is, how can I add 1 more column for the counting of the missing number.
It should be 1 for the first row, and 2 for the second row accroding to the missing number. 

Is there anyway we can count the total number missing as well, in this case is 3. 
Thank you for your help and support 🙂







  • Hi MightyRabbit ,

     

    You could try an additional measure something like this to count at the row level:

     

    _noofMissing =
    LEN([Missing_No]) - LEN(SUBSTITUTE([Missing_No], ",", "")) + 1

     

     

    You could further try using the above measure within a SUMX to iterate over one of your tmp tables and sum up the total.

     

    Pete

2 Replies

  • Hi MightyRabbit ,

     

    You could try an additional measure something like this to count at the row level:

     

    _noofMissing =
    LEN([Missing_No]) - LEN(SUBSTITUTE([Missing_No], ",", "")) + 1

     

     

    You could further try using the above measure within a SUMX to iterate over one of your tmp tables and sum up the total.

     

    Pete

  • MightyRabbit's avatar
    MightyRabbit
    Frequent Visitor

    Hi BA_Pete ,

    Thank you very much, it helps 🙂 Could you please elborate how could I use the SUMX against the tmp table, I have above, it seems that it only take the exisiting table "Sheet1" value only. 

    Thanks,