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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Nishlija995
New Member

Card to return recent value/blank and go in history

Hello,

 

I want to track KPI every working day, KPI is always signed for a day before, also if user didn't provide data it will show (blank) which is also good. What I want to achieve is to also be able to set filter and go in history in each week/month/quaral, but I am unable to do that with this code, it is always returning (blank), probably because I filter it by "today()" but I'm not sure what to modify to achieve this.

 

My code so far for card1 (single line each day)

card1 = 
If(WEEKDAY(today()) = 2,
CALCULATE (
    AVERAGE( db_signedData[Actual] ),
    Filter(db_signedData, db_signedData[KPI] = "foo" && db_signedData[created_date].[Date] = today()-3)),
CALCULATE (
    AVERAGE( db_signedData[Actual] ),
    Filter(db_signedData, db_signedData[KPI] = "foo" && db_signedData[created_date].[Date] = today()-1)))

 

Code so far for card2 (sum for whole week):

card2 = 
If(WEEKDAY(today()) = 2,
CALCULATE (
    sum( db_signedData[Actual] ),
    Filter(db_signedData, db_signedData[KPI] = "foo" && db_signedData[cw] = WEEKNUM(today())-1)),
CALCULATE (
    sum( db_signedData[Actual] ),
    Filter(db_signedData, db_signedData[KPI] = "foo" && db_signedData[cw] = WEEKNUM(today()))))

 

1 ACCEPTED SOLUTION

HI @Nishlija995,

It sounds like you want to use slicer to achieve selector effect instead of the filter.

If that is the case, I'd like to suggest you creating a unconned tale as source slicer, then you can extract the selection to interaction with formula calculation ranges:

card1 =
VAR selection =
    MAX ( Table[Date] )
RETURN
    IF (
        WEEKDAY ( selection ) = 2,
        CALCULATE (
            AVERAGE ( db_signedData[Actual] ),
            FILTER (
                ALLSELECTED ( db_signedData ),
                db_signedData[KPI] = "foo"
                    && db_signedData[created_date] = selection - 3
            )
        ),
        CALCULATE (
            AVERAGE ( db_signedData[Actual] ),
            FILTER (
                ALLSELECTED ( db_signedData ),
                db_signedData[KPI] = "foo"
                    && db_signedData[created_date] = selection - 1
            )
        )
    )

card2 =
VAR selection =
    MAX ( Table[Date] )
RETURN
    IF (
        WEEKDAY ( selection ) = 2,
        CALCULATE (
            SUM ( db_signedData[Actual] ),
            FILTER (
                ALLSELECTED ( db_signedData ),
                db_signedData[KPI] = "foo"
                    && db_signedData[cw]
                        = WEEKNUM ( selection ) - 1
            )
        ),
        CALCULATE (
            SUM ( db_signedData[Actual] ),
            FILTER (
                ALLSELECTED ( db_signedData ),
                db_signedData[KPI] = "foo"
                    && db_signedData[cw] = WEEKNUM ( selection )
            )
        )
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

3 REPLIES 3
v-shex-msft
Community Support
Community Support

Hi @Nishlija995,

The filter effect will apply to the visual to filter records at first with high priority from the table relationship mappings.

If you want to use slicer to achieve selector effects, I’d like to suggest you break the current date filter effect and add ALLSELECTED function to your expression to help records correctly filter table ranges.

card1 =
IF (
    WEEKDAY ( TODAY () ) = 2,
    CALCULATE (
        AVERAGE ( db_signedData[Actual] ),
        FILTER (
            ALLSELECTED ( db_signedData ),
            db_signedData[KPI] = "foo"
                && db_signedData[created_date]
                    = TODAY () - 3
        )
    ),
    CALCULATE (
        AVERAGE ( db_signedData[Actual] ),
        FILTER (
            ALLSELECTED ( db_signedData ),
            db_signedData[KPI] = "foo"
                && db_signedData[created_date]
                    = TODAY () - 1
        )
    )
)

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Hello @v-shex-msft ,

Thank you for reply.

I'm not sure that this is right code for me, maybe I didn't explained well.

One way is to have kinda "dynamic" slicer, which will if todays is monday return records for last week, and if today is any other day to return current week. Also, to have fuction to return any other week choosen in slicer (average/sum for selected week).

HI @Nishlija995,

It sounds like you want to use slicer to achieve selector effect instead of the filter.

If that is the case, I'd like to suggest you creating a unconned tale as source slicer, then you can extract the selection to interaction with formula calculation ranges:

card1 =
VAR selection =
    MAX ( Table[Date] )
RETURN
    IF (
        WEEKDAY ( selection ) = 2,
        CALCULATE (
            AVERAGE ( db_signedData[Actual] ),
            FILTER (
                ALLSELECTED ( db_signedData ),
                db_signedData[KPI] = "foo"
                    && db_signedData[created_date] = selection - 3
            )
        ),
        CALCULATE (
            AVERAGE ( db_signedData[Actual] ),
            FILTER (
                ALLSELECTED ( db_signedData ),
                db_signedData[KPI] = "foo"
                    && db_signedData[created_date] = selection - 1
            )
        )
    )

card2 =
VAR selection =
    MAX ( Table[Date] )
RETURN
    IF (
        WEEKDAY ( selection ) = 2,
        CALCULATE (
            SUM ( db_signedData[Actual] ),
            FILTER (
                ALLSELECTED ( db_signedData ),
                db_signedData[KPI] = "foo"
                    && db_signedData[cw]
                        = WEEKNUM ( selection ) - 1
            )
        ),
        CALCULATE (
            SUM ( db_signedData[Actual] ),
            FILTER (
                ALLSELECTED ( db_signedData ),
                db_signedData[KPI] = "foo"
                    && db_signedData[cw] = WEEKNUM ( selection )
            )
        )
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.