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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
KStout
Frequent Visitor

Elephant Data: Want to filter THEN transform the data and run calculations in report view

Hi! I am creating animal sctivity budgets. To do this, I first need to calculate the % of each behavior observed each day and then take the daily average %. Using AverageX, I get incorrect numbers calculated becuase it does not know how to account 0 into the average for behavior/date combinations it doesnt see. 

Currently, I have been working around this by transforming my data in PowerQuery or with DAX, then using Average(Mean Daily % Observed). However, creating all possible combinations of date, individual, behavior, requires a lot of computation power and slows down my report. Plus it makes the visuals unable to be filtered by slicers on the page that are more granular than the date. ie) I cannot filter these tables by hour becuase in PowerBI, the program transforms, calculates daily %, then filters, then calculates mean daily %. I need it to filter, then transform, calculate daily %, then calculate mean daily %.  

How can I create something that can achieve the same calculations and be filterable with the hour time slider? Attached is a subset of the data on elephants :).

Tis DAX code doesn work becuase again, the table is generated BEFORE filters are applied.

Daily % Table Made with DAX =
VAR AllCombos =
    ADDCOLUMNS(
        CROSSJOIN(
            VALUES('Raw Data'[Date]), VALUES('Raw Data'[Focal Name]),
            FILTER(VALUES('Raw Data'[Behavior]), NOT(ISBLANK('Raw Data'[Behavior])) )),
        "DailyTotal",
            CALCULATE(
                SUM('Raw Data'[BCount]),
                ALLEXCEPT('Raw Data', 'Raw Data'[Date])
            ),
        "DailyBehaviorCount",
            COALESCE(CALCULATE(
                SUM('Raw Data'[BCount]),
                ALLEXCEPT('Raw Data', 'Raw Data'[Date]),
                'Raw Data'[Behavior] = EARLIER('Raw Data'[Behavior]) && 'Raw Data'[Focal Name] = EARLIER('Raw Data'[Focal Name])
            ), 0)
           
    )

VAR WithPercentages =
    ADDCOLUMNS(
        AllCombos,
        "DailyPct",
            IF([DailyTotal] = 0, BLANK(), DIVIDE([DailyBehaviorCount], [DailyTotal], 0)
    ))

RETURN

   WithPercentages

Focal NameDateBehaviorLocationHour
Tonga10/15/25RestNorth8
Tonga10/15/25RestNorth8
Tonga10/15/25EatSouth9
Tonga10/15/25RestNorth9
Tonga10/15/25WalkNorth10
Tonga10/16/25DrinkSouth8
Tonga10/16/25RestSouth8
Tonga10/16/25WalkSouth8

Rafiki

10/16/25WalkSouth8
Rafiki10/16/25RestSouth9
Rafiki10/16/25WalkNorth9
Tonga10/16/25WalkNorth9
Tonga10/16/25RestSouth10

 

4 REPLIES 4
v-echaithra
Community Support
Community Support

Hi @KStout ,

Just following up to see if the Response provided was helpful in addressing the issue. if the issue still persists Feel free to reach out if you need any further clarification or assistance.


Best regards,
Chaithra E.

parry2k
Super User
Super User

@KStout you should create a measure for average instead of a calculated table, and that measure will respect the filter/slicer selection.

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Hi @KStout ,

Thank you for reaching out to Microsoft Community.

Calculate the total count of all behaviors observed for a specific date and individual, respecting slicers and filters.

DailyTotal = CALCULATE(
SUM('Raw Data'[BCount]),
ALLEXCEPT('Raw Data', 'Raw Data'[Date], 'Raw Data'[Focal Name]))

Calculate the count of behaviors observed for each behavior and individual, again respecting slicers.

BehaviorCount = CALCULATE(
SUM('Raw Data'[BCount]),
ALLEXCEPT('Raw Data', 'Raw Data'[Date], 'Raw Data'[Focal Name], 'Raw Data'[Behavior]))


Calculate the Daily Behavior Percentage which is the key measure, it calculates the percentage of each behavior observed for each individual and day.

DailyPct = VAR DailyTotalValue = [DailyTotal]
VAR BehaviorCountValue = [BehaviorCount]
RETURN
IF(
DailyTotalValue = 0,
BLANK(),
DIVIDE(BehaviorCountValue, DailyTotalValue, 0))

 

Now calculate the mean daily percentage for all behaviors across different time slices example by hour:

AverageDailyPct = AVERAGEX(
VALUES('Raw Data'[Date]),
[DailyPct])

Hope this will help.
Thank you.

Hi, thank you, this is so close! Unfortunely, my numbers are a tad off from what they need to be. I doubled checked and ran the calculations in Excel and the Power Query Activity budget I created was correct. The one made with measures was just slightly off. Do you have any ideas why?

KStout_0-1762553933296.png

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors