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

The Fabric Community site will be in read-only mode on Monday, Feb 24 from 12:01 AM to 8 AM PST for scheduled upgrades.

Reply
dw700d
Post Patron
Post Patron

using Dax Formula for an entire Table?

 

Good day, I have a data set that includes 45 different questions with Yes, No and N/A answers. I used the formula below to calculate how many times a question was answered with a Yes, No or N/A. I would like to avoid having to enter these formulas for the other 44 questions in my data set. That would take all day 😞 . Is there a way to apply these formulas to my entire table? I have also included a sample data set below. Thanks for your help

 

Yes = CALCULATE(count(Sheet1[Column1]),Sheet1[Column1] = "yes"
No = CALCULATE(count(Sheet1[Column1]),Sheet1[Column1] = "No"

 

N/A = CALCULATE(count(Sheet1[Column1]),Sheet1[Column1] = "N/A"

 

StudentSiteDateIs the Ball WhiteIs the Ball BlueIst the ball BrownIs the Ball redIs the ball pinkIs the Ball Yellow
1Jamaica12/1/2018YesYesYesNoYesYes
2Columbia12/3/2018YesYesYesNoNoNo
54Mexico11/1/2018NOYesYesYesNoNo
4Newyork11/4/2018noYesYesYesNoNo
5Jamaica12/3/2018N/AYesNoYesNoNo
43Columbia11/1/2018N/AYesYesYesNoYes
32Mexico11/4/2018noYesYesNoNoNo
9Newyork11/1/2018N/AYesYesYesNoNo
12Alabama11/4/2018noYesN/AYesNoYes
23Columbia12/1/2018YesYesYesYesNoNo
56Jamaica12/3/2018YesYesYesYesNoNo
75Bogota11/1/2018YesYesYesYesNoYes
432Bogota11/4/2018YesYesYesYesNoYes
1 ACCEPTED SOLUTION
LivioLanzo
Solution Sage
Solution Sage

Hi @dw700d,

you can apply a transformation to your data which unpivots the questions columns, you can do it with this Power Query:

 

 

let

Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUfJKzE3MTE4EsgyN9A31jQwMLYDsyNRiNNIvH0UgVidayQjIds7PKc1NyoTqNyagH0aAdJuaANm+qRWZySBBQ0OE5WhWoZsA0gzS65daXplflA3RbEKCZlN0b8Od7afviM3DKDYbo/ka2eFI2rGGHcgAYyM0f+N2OkaYWaJ7mziroboNQTY75iQmAf2O22qsYQCObnSf400vWILdDGe4E6PdHBRtTvnp+SXowY5XN8z1JuBwR9ZvQrz+WAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Student = _t, Site = _t, Date = _t, #"Is the Ball White" = _t, #"Is the Ball Blue" = _t, #"Ist the ball Brown" = _t, #"Is the Ball red" = _t, #"Is the ball pink" = _t, #"Is the Ball Yellow" = _t]),

ChangedType = Table.TransformColumnTypes(Source,{{"Student", Int64.Type}, {"Site", type text}, {"Date", type date}, {"Is the Ball White", type text}, {"Is the Ball Blue", type text}, {"Ist the ball Brown", type text}, {"Is the Ball red", type text}, {"Is the ball pink", type text}, {"Is the Ball Yellow", type text}}),

UnpivotedOtherColumns = Table.UnpivotOtherColumns(ChangedType, {"Student", "Site", "Date"}, "Question", "Response")

in

UnpivotedOtherColumns

 

 

then one measure does it all: NumberOfResponses = COUNTROWS( Data ) drop the questions on the matrix rows and the response on the matrix column

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

View solution in original post

2 REPLIES 2
LivioLanzo
Solution Sage
Solution Sage

Hi @dw700d,

you can apply a transformation to your data which unpivots the questions columns, you can do it with this Power Query:

 

 

let

Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUfJKzE3MTE4EsgyN9A31jQwMLYDsyNRiNNIvH0UgVidayQjIds7PKc1NyoTqNyagH0aAdJuaANm+qRWZySBBQ0OE5WhWoZsA0gzS65daXplflA3RbEKCZlN0b8Od7afviM3DKDYbo/ka2eFI2rGGHcgAYyM0f+N2OkaYWaJ7mziroboNQTY75iQmAf2O22qsYQCObnSf400vWILdDGe4E6PdHBRtTvnp+SXowY5XN8z1JuBwR9ZvQrz+WAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Student = _t, Site = _t, Date = _t, #"Is the Ball White" = _t, #"Is the Ball Blue" = _t, #"Ist the ball Brown" = _t, #"Is the Ball red" = _t, #"Is the ball pink" = _t, #"Is the Ball Yellow" = _t]),

ChangedType = Table.TransformColumnTypes(Source,{{"Student", Int64.Type}, {"Site", type text}, {"Date", type date}, {"Is the Ball White", type text}, {"Is the Ball Blue", type text}, {"Ist the ball Brown", type text}, {"Is the Ball red", type text}, {"Is the ball pink", type text}, {"Is the Ball Yellow", type text}}),

UnpivotedOtherColumns = Table.UnpivotOtherColumns(ChangedType, {"Student", "Site", "Date"}, "Question", "Response")

in

UnpivotedOtherColumns

 

 

then one measure does it all: NumberOfResponses = COUNTROWS( Data ) drop the questions on the matrix rows and the response on the matrix column

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

sorry but not sure why the posts suddenly get pasted in such a bad format

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

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