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
Emm
Frequent Visitor

How to get the two fixed columns to update when filter by date?

Based on the previous post, I've modified the fixed table to include a Frequency column. I want the Minimum and Targe columns to update when filtering by date (with the date column coming from the database table, Table1).  Below is the DAX i'm using, but I'm not sure where I went wrong - both the Minimum and Target columns don't update when filtered by date. Please help! Thank you!!

 

Testing = VAR SourceName = SELECTEDVALUE(TargetData[Source])
VAR Frequency = SELECTEDVALUE(TargetData[Frequency])
VAR BaseMin = SELECTEDVALUE(TargetData[Minimum])
VAR BaseTarget = SELECTEDVALUE(TargetData[Target])

-- Get number of distinct days in the BatchData table (with selected date range)
VAR SelectedDates =
CALCULATETABLE(
VALUES(DateTable[Date]),
ALLSELECTED(DateTable)
)
VAR NumDays = COUNTROWS(SelectedDates)

-- Adjust multiplier based on Frequency
VAR Multiplier =
SWITCH(
TRUE(),
Frequency = "Daily", NumDays,

Frequency = "Business Days", DIVIDE(NumDays, 5, 0).
Frequency = "Weekly", DIVIDE(NumDays, 7, 0),
Frequency = "Monthly", DIVIDE(NumDays, 30, 0),
1
)

-- Calculate scaled Minimum and Target
VAR MinValue = BaseMin * Multiplier
VAR TargetValue = BaseTarget * Multiplier

 

VAR SoldValue =
CALCULATE(
COUNT(BatchData[BatchId]),
FILTER(BatchData, BatchData[Source] = SourceName)
)

RETURN
IF(
SoldValue = SoldValue < MinValue,
SWITCH(
TRUE(),
Frequency = "Monthly", "#008000",  -- Green
Frequency = "Weekly", "#FFFF00", -- Yellow
"#FF0000" -- Red for Daily
),
BLANK()
)

 

Table1 (from the database)

FileNameItemsDateTotalNumTotalSpoiled
ap20250228-01Apple3/4/202520010
ap20250228-02Apple3/4/202515030
p20250228-01Pear3/4/2025453
p20250228-02Pear3/4/202510010
p20250228-03Pear3/4/202510010
Or20250228-01Orange3/4/202515020
Or20250228-02Orange3/4/202510010
Or20250228-03Orange3/4/2025800
Or20250228-04Orange3/4/2025650
Or20250228-05Orange3/4/2025804
Or20250228-06Orange3/4/2025905
Or20250228-07Orange3/4/2025550
On20250228-01Onion3/4/202520010
On20250228-02Onion3/4/20251005
On20250228-03Onion3/4/202518020

 

Table2 (fixed table)

SourceFrequencyTargetMinimum
AppleDaily23
OrangeDaily74
PearBussiness Days32
OnionWeekly31
PepperMonthly11

 

Result: 

SourceFrequencySoldTargetMinimum
AppleDaily243
OrangeDaily754
PearBusiness Days332
OnionWeekly321
PepperMonthly011

 

When filtered by Date, the Target and Minimum values should change accordingly.  For example, for Apple: Minimum should change from 3 to 6 and the Target from 4 to 8 for 2 days; for 3 days, the Minimum should change from 6 to 9 and the Target from 8 to 12, and so on.  Also, if the Sold value is less than the Minimum should hightlighted with color. The DAX formula doesn't seem to be working as expected. I'd appreciate any help. Thank you in advance!

 

Result for 2 days:

SourceFrequencySoldTargetMinimum
AppleDaily786
OrangeDaily14108
PearBusiness Days664
OnionWeekly321
PepperMonthly011

 

 

 

 

 

1 ACCEPTED SOLUTION
v-achippa
Community Support
Community Support

Hi @Emm,

 

Thank you for the response and providing the full dataset. Please make sure you have a proper DateTable in your model which includes continuous dates and columns like IsBusinessDay, MonthYear, etc. Please try to use these below DAX measures:

 

Sold Count:

Sold =

CALCULATE(

    COUNTROWS('Table1'),

    ALLEXCEPT('Table1', 'Table1'[Source])

)

 

Days Count:

Days Count =

VAR SelectedSource = SELECTEDVALUE('Table2'[Source])

VAR Frequency = LOOKUPVALUE('Table2'[Frequency], 'Table2'[Source], SelectedSource)

VAR Dates = VALUES('DateTable'[Date])

RETURN

SWITCH(

    TRUE(),

    Frequency = "Daily", COUNTROWS(Dates),

    Frequency = "Business Days", CALCULATE(COUNTROWS(Dates), 'DateTable'[IsBusinessDay] = TRUE),

    Frequency = "Weekly", INT(COUNTROWS(Dates) / 7) + IF(MOD(COUNTROWS(Dates), 7) > 0, 1, 0),

    Frequency = "Monthly", DISTINCTCOUNT('DateTable'[MonthYear]),

    BLANK()

)

 

Dynamic Target =

LOOKUPVALUE('Table2'[Target], 'Table2'[Source], SELECTEDVALUE('Table1'[Source])) * [Days Count]

 

Dynamic Minimum =

LOOKUPVALUE('Table2'[Minimum], 'Table2'[Source], SELECTEDVALUE('Table1'[Source])) * [Days Count]

 

Status for highlighting:

Highlight Alert =

IF([Sold Count] < [Dynamic Minimum], 1, 0)

 

We can display this in a matrix or table visual.

 

If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it! 

 

Thanks and regards,

Anjan Kumar Chippa

View solution in original post

7 REPLIES 7
v-achippa
Community Support
Community Support

Hi @Emm,

 

Thank you for reaching out to Microsoft Fabric Community.

 

As the super user mentioned that in your description you mentioned that Apple has a base Target of 4 but in your Table2 it is listed as 2. Could you please confirm which one is correct?

Also, since Table1 only contains data for one date (3/4/2025) could you clarify how you are calculating the Sold value over multiple days? If you are expecting results for a date range, it would be helpful if you could provide additional data rows for those dates so that we can look more into the issue and provide you the best solution possible.

 

Thanks and regards,

Anjan Kumar Chippa

Emm
Frequent Visitor

Hi!

Sorry! Here is the corrected data as below.  To calculate the Sold value is counting the number of the FileNames.

 

Table1

FileNameItemsDateTotalNumTotalSpoiled
ap20250304-01Apple3/4/202520010
ap20250304-02Apple3/4/202515030
p20250304-01Pear3/4/2025453
p20250304-02Pear3/4/202510010
p20250304-03Pear3/4/202510010
Or20250304-01Orange3/4/202515020
Or20250304-02Orange3/4/202510010
Or20250304-03Orange3/4/2025800
Or20250304-04Orange3/4/2025650
Or20250304-05Orange3/4/2025804
Or20250304-06Orange3/4/2025905
Or20250304-07Orange3/4/2025550
On20250304-01Onion3/4/202520010
On20250304-02Onion3/4/20251005
On20250304-03Onion3/4/202518020
ap20250305-01Apple3/5/20251000
ap20250305-02Apple3/5/2025805
ap20250305-03Apple3/5/202515020
ap20250305-04Apple3/5/202510010
p20250305-01Pear3/5/20256010
p20250305-02Pear3/5/20251305
p20250305-03Pear3/5/202510010
Or20250305-01Orange3/5/202513010
Or20250305-02Orange3/5/202512010
Or20250305-03Orange3/5/20251000
Or20250305-04Orange3/5/2025800
Or20250305-05Orange3/5/2025604
Or20250305-06Orange3/5/2025905
Or20250305-07Orange3/5/2025550
Or20250305-08Orange3/5/2025505
On20250305-01Onion3/5/202520020
On20250305-02Onion3/5/20251005
On20250305-03Onion3/5/202518015
ap20250306-01Apple3/6/20251000
ap20250306-02Apple3/6/2025805
ap20250306-03Apple3/6/202515010
ap20250306-04Apple3/6/20251005
p20250306-01Pear3/6/20256010
p20250306-02Pear3/6/20251305
p20250306-03Pear3/6/202510010
Or20250306-01Orange3/6/20251305
Or20250306-02Orange3/6/20251203
Or20250306-03Orange3/6/20251000
Or20250306-04Orange3/6/2025800
Or20250306-05Orange3/6/2025608
Or20250306-06Orange3/6/2025905
Or20250306-07Orange3/6/2025550

 

Table2 (Fixed Table)

SourceFrequencyTargetMinimum
AppleDaily43
OrangeDaily54
PearBussiness Days32
OnionWeekly21
PepperMonthly11

 

Result for 1 day:

SourceFrequencySoldTargetMinimum
AppleDaily243
OrangeDaily754
PearBusiness Days332
OnionWeekly321
PepperMonthly011

 

Results for 2 days:

SourceFrequencySoldTargetMinimum
AppleDaily686
OrangeDaily15108
PearBusiness Days664
OnionWeekly321
PepperMonthly011

 

Result for 3 days:

SourceFrequencySoldTargetMinimum
AppleDaily10129
OrangeDaily221512
PearBusiness Days996
OnionWeekly321
PepperMonthly011

 

Thank you!

 

 

 

v-achippa
Community Support
Community Support

Hi @Emm,

 

Thank you for the response and providing the full dataset. Please make sure you have a proper DateTable in your model which includes continuous dates and columns like IsBusinessDay, MonthYear, etc. Please try to use these below DAX measures:

 

Sold Count:

Sold =

CALCULATE(

    COUNTROWS('Table1'),

    ALLEXCEPT('Table1', 'Table1'[Source])

)

 

Days Count:

Days Count =

VAR SelectedSource = SELECTEDVALUE('Table2'[Source])

VAR Frequency = LOOKUPVALUE('Table2'[Frequency], 'Table2'[Source], SelectedSource)

VAR Dates = VALUES('DateTable'[Date])

RETURN

SWITCH(

    TRUE(),

    Frequency = "Daily", COUNTROWS(Dates),

    Frequency = "Business Days", CALCULATE(COUNTROWS(Dates), 'DateTable'[IsBusinessDay] = TRUE),

    Frequency = "Weekly", INT(COUNTROWS(Dates) / 7) + IF(MOD(COUNTROWS(Dates), 7) > 0, 1, 0),

    Frequency = "Monthly", DISTINCTCOUNT('DateTable'[MonthYear]),

    BLANK()

)

 

Dynamic Target =

LOOKUPVALUE('Table2'[Target], 'Table2'[Source], SELECTEDVALUE('Table1'[Source])) * [Days Count]

 

Dynamic Minimum =

LOOKUPVALUE('Table2'[Minimum], 'Table2'[Source], SELECTEDVALUE('Table1'[Source])) * [Days Count]

 

Status for highlighting:

Highlight Alert =

IF([Sold Count] < [Dynamic Minimum], 1, 0)

 

We can display this in a matrix or table visual.

 

If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it! 

 

Thanks and regards,

Anjan Kumar Chippa

Hi @Emm,

 

As we haven’t heard back from you, we wanted to kindly follow up to check if the solution I have provided for the issue worked? or let us know if you need any further assistance.
If my response addressed, please mark it as "Accept as solution" and click "Yes" if you found it helpful.

 

Thanks and regards,

Anjan Kumar Chippa

Hi @Emm,

 

We wanted to kindly follow up to check if the solution I have provided for the issue worked.
If my response addressed, please mark it as "Accept as solution" and click "Yes" if you found it helpful.

 

Thanks and regards,

Anjan Kumar Chippa

Hi @Emm,

 

As we haven’t heard back from you, we wanted to kindly follow up to check if the solution I have provided for the issue worked.
If my response addressed, please mark it as "Accept as solution" and click "Yes" if you found it helpful.

 

Thanks and regards,

Anjan Kumar Chippa

Irwan
Super User
Super User

hello @Emm 

 

what is the target for apple? is it 2 or 4?
because in your description, you said 4 but in your fixed table, it says 2.

Irwan_0-1747697683918.png

Irwan_1-1747697701245.png

 

also how do you calculate Sold value? it seems you only provided one day data in your table1.

 

Thank you.

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