Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hi All,
This is the data model
The Product Table is connect to fact table by product key
Store list is connect to fact table by customer key
Date is connected to Fact table but not to store list
Fact table is a monthly data. It consist of sales rep, date, sales amount. I get the data on monthly basis and I append the data.
Store List consist of full list of store in the organization. This is also a monthly data. I append each month data. The reason to append this data is I want to preserve the histrorical data.
My goal/aim
Total Customer :
1. User select the date (say December), then it should filter Store List to Dec Data.
2. Then Filter the Fact Table data from Oct 01 to Dec 31.
3. Then find the common store between (1) and (2)
The code I used to find this is
Solved! Go to Solution.
Hi @Mkrishna ,
It seems like you're facing a challenge with DAX date filtering when trying to calculate the number of stores with Brand BB for the maximum visit date within a specific period.
Let's address the problem step by step:
1. Filtering Store List to Selected Month: You've mentioned that when selecting a month other than December, the Store List correctly filters to that month. This is expected behavior as per your current DAX formula.
2. Filtering Fact Table to a 3-Month Period: The issue arises when you want the Fact Table to filter to a three-month period ending with the selected month. Your current code snippet seems to filter the Fact Table only for the selected month, not the entire period.
To resolve this, we need to adjust your DAX measure to ensure that it considers the entire three-month period. Here's a revised version of your 'Nos. of Store' measure:
Nos. of Store =
VAR SelectedEndDate = MAX('Date'[Date])
VAR StartDate = STARTOFMONTH(DATEADD(SelectedEndDate, -2, MONTH))
VAR EndDate = EOMONTH(SelectedEndDate, 0)
VAR MonthlyStore =
CALCULATETABLE(
VALUES('Store List'[Store Number]),
TREATAS(VALUES('Date'[Date]), 'Store List'[Date]),
'Store List'[Date] = MIN('Date'[Date])
)
VAR MaxDate =
CALCULATE(
MAX('Fact Table'[Visit Date]),
FILTER(
ALL('Fact Table'),
'Fact Table'[Store Number] IN MonthlyStore &&
'Fact Table'[Visit Date] >= StartDate &&
'Fact Table'[Visit Date] <= EndDate
)
)
VAR STORE_COUNT =
CALCULATE(
COUNTROWS(
FILTER(
'Fact Table',
'Fact Table'[Store Number] IN MonthlyStore &&
'Fact Table'[Visit Date] = MaxDate &&
'Fact Table'[Brand] = "BB"
)
),
REMOVEFILTERS('Date'),
KEEPFILTERS(VALUES('Date'[Date]))
)
RETURN
IF(STORE_COUNT > 0, 1, 0)
-Please note the following changes:
- Defined 'StartDate' and 'EndDate' to represent the start and end of the three-month period.
- Adjusted the 'FILTER' function within 'MaxDate' to consider the entire period between 'StartDate' and 'EndDate'.
- Added a condition to check for Brand BB in the 'STORE_COUNT' calculation.
Please try this revised measure and see if it produces the expected results.
Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @Mkrishna ,
It seems like you're facing a challenge with DAX date filtering when trying to calculate the number of stores with Brand BB for the maximum visit date within a specific period.
Let's address the problem step by step:
1. Filtering Store List to Selected Month: You've mentioned that when selecting a month other than December, the Store List correctly filters to that month. This is expected behavior as per your current DAX formula.
2. Filtering Fact Table to a 3-Month Period: The issue arises when you want the Fact Table to filter to a three-month period ending with the selected month. Your current code snippet seems to filter the Fact Table only for the selected month, not the entire period.
To resolve this, we need to adjust your DAX measure to ensure that it considers the entire three-month period. Here's a revised version of your 'Nos. of Store' measure:
Nos. of Store =
VAR SelectedEndDate = MAX('Date'[Date])
VAR StartDate = STARTOFMONTH(DATEADD(SelectedEndDate, -2, MONTH))
VAR EndDate = EOMONTH(SelectedEndDate, 0)
VAR MonthlyStore =
CALCULATETABLE(
VALUES('Store List'[Store Number]),
TREATAS(VALUES('Date'[Date]), 'Store List'[Date]),
'Store List'[Date] = MIN('Date'[Date])
)
VAR MaxDate =
CALCULATE(
MAX('Fact Table'[Visit Date]),
FILTER(
ALL('Fact Table'),
'Fact Table'[Store Number] IN MonthlyStore &&
'Fact Table'[Visit Date] >= StartDate &&
'Fact Table'[Visit Date] <= EndDate
)
)
VAR STORE_COUNT =
CALCULATE(
COUNTROWS(
FILTER(
'Fact Table',
'Fact Table'[Store Number] IN MonthlyStore &&
'Fact Table'[Visit Date] = MaxDate &&
'Fact Table'[Brand] = "BB"
)
),
REMOVEFILTERS('Date'),
KEEPFILTERS(VALUES('Date'[Date]))
)
RETURN
IF(STORE_COUNT > 0, 1, 0)
-Please note the following changes:
- Defined 'StartDate' and 'EndDate' to represent the start and end of the three-month period.
- Adjusted the 'FILTER' function within 'MaxDate' to consider the entire period between 'StartDate' and 'EndDate'.
- Added a condition to check for Brand BB in the 'STORE_COUNT' calculation.
Please try this revised measure and see if it produces the expected results.
Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
@Mkrishna Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882
Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490
The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 41 | |
| 38 | |
| 36 | |
| 31 | |
| 28 |
| User | Count |
|---|---|
| 129 | |
| 88 | |
| 79 | |
| 68 | |
| 63 |