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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
prashantg364
Helper II
Helper II

DAX help

Original data table has 3 columns - SiteID, time, IFHO_INTRA.
need to calculate the number of days IFHO_INTRA >=98 under a new column "Pass days"
the below table shows data table filtered from 6 Jan to 9 Jan and based on the date selection Pass days column created manually.

Example:
SiteID 3803, having IFHO_INTRA >=98 for all 4 days from the filetered days

SiteID 3810, having IFHO_INTRA >=98 for 3 days from the filetered days

SiteID 3869, having IFHO_INTRA >=98 for 3 days from the filetered days and for 6 Jan Data is blank, so consider it as fail. Blank data can be considered as fail.
SiteID 3873, having IFHO_INTRA >=98 for 0 days from the filetered days


How can i do it with DAX column, so that my Pass days changes based on the selected dates and IFHO_INTRA >=98.
Infact i want to do this only for last 5 dates in my data set.

 

SiteIDtimeIFHO_INTRAPass days
38036-1-2598.834
38037-1-2599.484
38038-1-25100.004
38039-1-2598.704
38106-1-2598.953
38107-1-2597.123
38108-1-2598.393
38109-1-2597.783
38356-1-2599.014
38357-1-2598.924
38358-1-2599.224
38359-1-2599.084
38696-1-25 3
38697-1-2599.593
38698-1-2599.743
38699-1-2599.453
38736-1-2597.600
38737-1-2597.870
38738-1-2596.730
38739-1-2597.370
39466-1-2597.570
39467-1-2592.690
39468-1-2596.290
39469-1-2593.960
39506-1-2589.781
39507-1-2593.851
39508-1-2592.831
39509-1-2599.051
39546-1-2594.980
39547-1-2596.870
39548-1-2596.190
39549-1-2596.650
40086-1-2597.563
40087-1-2599.353
40088-1-2599.133
40089-1-2599.223
40126-1-2599.542
40127-1-2599.772
40128-1-2597.772
40129-1-2597.852
1 ACCEPTED SOLUTION
sanalytics
Super User
Super User

@prashantg364 
i) How come 3810 will be 2? it should be 2. Check your data once again.
ii) It is not possible to dynamically apply slicer selections to a calculated column. Slicers impact visuals by defining the filter context, whereas calculated columns are evaluated during data refresh. both are different concepts.
if you want to have slicer impact on your table then suggesting you create measure instead of calculated column.
For measure you can refer below code

Pass days=
VAR _1 = 
CALCULATE(
    COUNTROWS(
      FILTER(
        'Table',[Total Intra] > 98
    )) , ALLSELECTED( 'Table'[time] )
)
VAR _Result = 
IF(
    ISBLANK( _1 ),0,
    _1
)
RETURN
_Result

below screenshot

sanalytics_1-1736503965018.png

 

For calculated column, you will have to manually select the last five days and then create the calculated column which @johnt75  has provided the solution.

 

let me know if you need pbix file.

Regards

sanalytics

 

 



View solution in original post

3 REPLIES 3
sanalytics
Super User
Super User

@prashantg364 
i) How come 3810 will be 2? it should be 2. Check your data once again.
ii) It is not possible to dynamically apply slicer selections to a calculated column. Slicers impact visuals by defining the filter context, whereas calculated columns are evaluated during data refresh. both are different concepts.
if you want to have slicer impact on your table then suggesting you create measure instead of calculated column.
For measure you can refer below code

Pass days=
VAR _1 = 
CALCULATE(
    COUNTROWS(
      FILTER(
        'Table',[Total Intra] > 98
    )) , ALLSELECTED( 'Table'[time] )
)
VAR _Result = 
IF(
    ISBLANK( _1 ),0,
    _1
)
RETURN
_Result

below screenshot

sanalytics_1-1736503965018.png

 

For calculated column, you will have to manually select the last five days and then create the calculated column which @johnt75  has provided the solution.

 

let me know if you need pbix file.

Regards

sanalytics

 

 



Poojara_D12
Super User
Super User

To calculate "Pass Days" (days where IFHO_INTRA >= 98 for each SiteID) dynamically in Power BI:

 

Dynamic Measure

Use this measure for dynamic filtering (e.g., last 5 days):

 

Pass Days =
VAR Last5Dates =
    TOPN(5, ALL('YourTable'[time]), 'YourTable'[time], DESC) // Get last 5 dates
VAR FilteredTable =
    FILTER(
        'YourTable',
        'YourTable'[time] IN Last5Dates && 'YourTable'[IFHO_INTRA] >= 98
    )
RETURN
CALCULATE(
    COUNTROWS(FILTEREDTABLE),
    DISTINCT('YourTable'[SiteID])
)

 

Static Column

If a static result is needed, use this calculated column:

 

Pass Days =
CALCULATE(
    COUNT('YourTable'[time]),
    FILTER(
        'YourTable',
        'YourTable'[SiteID] = EARLIER('YourTable'[SiteID]) && 'YourTable'[IFHO_INTRA] >= 98
    )
)

 

 

Logic

1. Measure dynamically calculates "Pass Days" for the last 5 dates.

2. Column calculates it statically for all rows in the dataset.

3. Blanks in IFHO_INTRA are treated as fails (< 98).

 

This ensures the "Pass Days" dynamically updates based on the date filter or slicer.

 

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Poojara
Data Analyst | MSBI Developer | Power BI Consultant
Consider Subscribing my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS 

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a "Kudos"

Kind Regards,
Poojara - Proud to be a Super User
Data Analyst | MSBI Developer | Power BI Consultant
Consider Subscribing my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS
johnt75
Super User
Super User

You can create a calculated column like

Pass Days =
VAR Last5Days =
    WINDOW (
        1,
        ABS,
        5,
        ABS,
        DISTINCT ( 'Table'[time] ),
        ORDERBY ( 'Table'[time], DESC )
    )
VAR Result =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        ALLEXCEPT ( 'Table', 'Table'[SiteID] ),
        Last5Days,
        'Table'[IFHO_INTRA] >= 98
    )
RETURN
    Result

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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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