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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Barendnu
Advocate III
Advocate III

CHISQ.TEST in DAX

in Excel, there's a handy function called CHISQ.TEST, which returns the value from the chi-squared (χ2) distribution for the statistic and the appropriate degrees of freedom.

 

I saw that many CHISQ-* functions are available in DAX (as shown on this Excel comparisation page), but the CHISQ.TEST function seems not to be available in DAX. We are specifically looking for this function, since we have a actual_range and expected_range in our dataset, and want to show the level of significance for differences (at <0.05).

 

In Excel, we do get the desired result, but I'm struggling to get the same result in DAX:

screenshotExcel.png

 


Any help would be greatly appreciated!

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

Since I don't know how your dimensions and data is set up, it's hard to write a formula for your situation but here's how I'd duplicate the calculation from the CHISQ.TEXT documentation you've linked.

 

Setup:

GenderDescriptionActualExpected
MenAgree5845.35
MenNeutral1117.56
MenDisagree1016.09
WomenAgree3547.65
WomenNeutral2518.44
WomenDisagree2316.91

 

DAX:

ChiSqTest =
VAR ChiStat =
    SUMX ( Survey, ( Survey[Actual] - Survey[Expected] ) ^ 2 / Survey[Expected] )
VAR DegreesFreedom =
    ( DISTINCTCOUNT ( Survey[Gender] ) - 1 ) * ( DISTINCTCOUNT ( Survey[Description] ) - 1 )
RETURN
    CHISQ.DIST.RT ( ChiStat, DegreesFreedom )

View solution in original post

2 REPLIES 2
AlexisOlson
Super User
Super User

Since I don't know how your dimensions and data is set up, it's hard to write a formula for your situation but here's how I'd duplicate the calculation from the CHISQ.TEXT documentation you've linked.

 

Setup:

GenderDescriptionActualExpected
MenAgree5845.35
MenNeutral1117.56
MenDisagree1016.09
WomenAgree3547.65
WomenNeutral2518.44
WomenDisagree2316.91

 

DAX:

ChiSqTest =
VAR ChiStat =
    SUMX ( Survey, ( Survey[Actual] - Survey[Expected] ) ^ 2 / Survey[Expected] )
VAR DegreesFreedom =
    ( DISTINCTCOUNT ( Survey[Gender] ) - 1 ) * ( DISTINCTCOUNT ( Survey[Description] ) - 1 )
RETURN
    CHISQ.DIST.RT ( ChiStat, DegreesFreedom )

Dear AlexisOlson,

 

That is brilliant! It does exactly what we want! No need for a built-in CHITEST function when we can write it in DAX this way 🙂 Thank you very much 👍

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors