Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
Anonymous
Not applicable

Display field value on rows and count in the total

Hi,

 

I have a unique requirement, where I need to display textual content applicable in the table rows, while displaying the distinct count of the same in total. Each field displayed in the table may be filtered.

Is it possible to create a DAX expression/ is there a work around to meet this requirement?

 

For example, in the snapshot below, I m displaying distinct count of Column B elements in the total.

However, the expression fails when there is a single element as it was not possible to distingish between a row item and total

 

DAX I used:

 

ColB or Distinct Count =
var _x = DISTINCTCOUNT(Test[ColB])
var _y = COUNTROWS(Test)
RETURN
IF(_y=1, IF(_x=1  ,  SELECTEDVALUE(Test[ColB]), "1"), _x & "")

 

 

As ExpectedAs Expected

 

IncorrectOutput.png

 

 

Sample data

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("XY7BCQAxCAR78Z1H1NjAWYak/zaSjSTgfQYZZsEIYmr0AQ5wp9mCBBJw4CgdcHrDdEVJ/8m3PVPA4TU7g7TSSfllZMfvF1y25Vw=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ColA = _t, ColB = _t, ColC = _t, ColD = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ColA", Int64.Type}, {"ColB", type text}, {"ColC", type text}, {"ColD", Int64.Type}})
in
    #"Changed Type"

 

Thanks,

Mannu

4 REPLIES 4
lbendlin
Super User
Super User

In this particular scenario ISINSCOPE is better than HASONEVALUE. That is not universally true.

 

Measure = if(isinscope(Query1[ColB]),max(Query1[ColB]),DISTINCTCOUNT(Query1[ColB]))

 

https://www.sqlbi.com/articles/distinguishing-hasonevalue-from-isinscope/ 

Anonymous
Not applicable

Thanks @lbendlin 

 

I m still unable to get the totals in. Infact now, Im unable to get the item values correctly (it shows count many a time)

 

regards,

Mannu

don't summarize any columns, enable "show items with no data"

Anonymous
Not applicable

Thanks again @lbendlin 

I have done the same. But then I see the distinct count on each row.

It only works oif I have Notiifcation Count column on table (which defeats the purpose of designing this Measure)

Combination of order No and Notification No are Unique in this table.

 

All fields are text fields. So converting it into text

No/Count = 

if(isinscope(Order[Notification No]),max(Order[Notification No]),DISTINCTCOUNT(Order[Notification No])&" ")

 

errorImg.PNGerrorImg-2.PNG

Thanks,

Mannu

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.