cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
stuartcorns
New Member

Using a function returns blank when using another function value

Hi, I was wondering if anyone could help - new to the community.

 

I have some DAX code that should return some student attendance for the previous week. However, I currently have to hard code the previous fiscal week number, when I place the value from the Calendar Dates table (Calculates the previous fiscal week from the current). This my code

 

 

Previous Week Attendance Measure = 
var _measure =
DIVIDE(
    CALCULATE(
        COUNT('AT_Session_Marks'[Session Mark]), 
        FILTER(AT_Session_Marks, 'AT_Session_Marks'[Absent] = TRUE), 
        FILTER('AT_Session_Marks', 'AT_Session_Marks'[Fiscal Week No] = 1)
    ), 
    CALCULATE(
        COUNT('AT_Session_Marks'[Session Mark]), 
        FILTER('AT_Session_Marks', 'AT_Session_Marks'[Fiscal Week No] = 1)
    ),
    0)
return
IF(ISBLANK(_measure), 0, _measure)

 

The above returns the correct amount.

 

Previous Week Attendance Measure = 
var _measure =
DIVIDE(
    CALCULATE(
        COUNT('AT_Session_Marks'[Session Mark]), 
        FILTER(AT_Session_Marks, 'AT_Session_Marks'[Absent] = TRUE), 
        FILTER('AT_Session_Marks', 'AT_Session_Marks'[Fiscal Week No] = 'Calendar Functions'[Previous Fiscal Week])
    ), 
    CALCULATE(
        COUNT('AT_Session_Marks'[Session Mark]), 
        FILTER('AT_Session_Marks', 'AT_Session_Marks'[Fiscal Week No] = 'Calendar Functions'[Previous Fiscal Week])
    ),
    0)
return
IF(ISBLANK(_measure), 0, _measure)

 

Whereas the above returns 0 despite the 'Calendar Functions'[Previous Fiscal Week] outputting the correct value.

 

Appreciate some guidance. TIA

1 ACCEPTED SOLUTION
daXtreme
Solution Sage
Solution Sage

Hi @stuartcorns 

 

Please change you model as soon as possible to a correct one, meaning a star schema. Your current model is not following Best Practices and therefore you'll very soon have multiple problems (you already have). Please, before you start doing any serious work with PBI, read this: Understand star schema and the importance for Power BI … (bing.com)

 

Also, you should never filter by a full table, especially by a fact table as this puts a lot of stress on the engine and DAX becomes slow to the point where you're going to get timeouts. The golden rule of DAX is: Never filter a table when you can filter a column.

View solution in original post

1 REPLY 1
daXtreme
Solution Sage
Solution Sage

Hi @stuartcorns 

 

Please change you model as soon as possible to a correct one, meaning a star schema. Your current model is not following Best Practices and therefore you'll very soon have multiple problems (you already have). Please, before you start doing any serious work with PBI, read this: Understand star schema and the importance for Power BI … (bing.com)

 

Also, you should never filter by a full table, especially by a fact table as this puts a lot of stress on the engine and DAX becomes slow to the point where you're going to get timeouts. The golden rule of DAX is: Never filter a table when you can filter a column.

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors