Forum Discussion

acolin's avatar
acolin
Frequent Visitor
3 years ago
Solved

Help to reference columns from a var table to another var table!

Hello, I really need help with this one. The problem is that I have a table with Users IDs (UIDs) and Devices IDs (DIDs), and I want to get through a MEASURE the values of how many DISTINCT COUNT of ...
  • v-yueyunzh-msft's avatar
    3 years ago

    Hi , acolin 

    Thanks for your sample data and detailed description.

    According to your description, in my thought , you want to create a measure to get the sum of [Distusrs] , like this:

    If this , you can refer to :
    (1)We can crecate a number as row headers:

    We do not need to create any relationship between tables.

    (2)You can create a measure like this:

    Measure = var _t =  ADDCOLUMNS('Table',"Distdisps" , CALCULATE(DISTINCTCOUNT('Table'[DID]) , 'Table'[UID]=EARLIER([UID]) ,ALL('Table'[DID])))
    var _t2 = ADDCOLUMNS( _t ,"Distusrs", var _Distdisps = [Distdisps] var _test = DISTINCT(SELECTCOLUMNS( FILTER(_t ,[Distdisps]=_Distdisps),"uid" ,[UID]))  return COUNTROWS(_test)     )
    var _cur_num =  VALUES('Number'[Column1])
    var _t3 = FILTER(_t2 , [Distdisps] in _cur_num)
    return
    SUMX(_t3 , [Distusrs])

     

    Then we can put this measure on  the visual like this , the result is as follows:

     

     

     

     

    If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem. (You can also upload you sample .pbix [without sensitive data] to the OneDrive and share with the OneDrive link to me ! )

    Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

     

    Best Regards,

    Aniya Zhang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly