Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hello,
I have a column "Valuation date" with dates like:
2024-02-06
2024-02-06
2024-02-06
2024-02-07
2024-02-07
2024-02-07
2024-02-09
2024-02-10
2024-02-10
2024-02-12
2024-02-12
2024-02-12
2024-02-12
I want to create a measure showing how many times i have this date in the column like:
2024-02-06 3
2024-02-06 3
2024-02-06 3
2024-02-07 3
2024-02-07 3
2024-02-07 3
2024-02-09 1
2024-02-10 2
2024-02-10 2
2024-02-12 4
2024-02-12 4
2024-02-12 4
2024-02-12 4
Please help with DAX. Thanks!
I'm assuming it's intended that you want the dates to display multiple times as well in the visual. This would typically mean either
a) you're not using a date table or
b) there are going to be more columns added to the display table and a date table is going to be used.
Either way, the following calculation should do the job for you. 'Table' in this case is going to be the table that your fact is (I.E. not the date table)
CountOfDates =
var _SelectedValueDate = SELECTEDVALUE('Table'[Date])
return
CALCULATE(
COUNTROWS('Table'),
ALL('Table'),
'Table'[Date] = _SelectedValueDate
)
Hi @NickDanger, it does not work. E.g. I should get 3 for 02-06, 1 for 02-09, 2 for 02-13 instead.
I think the expression takes numbers from ground table my visual is based on, but rows in my visual are filtered out. I need to count rows with the same valuation date on my visual below.
@Shota_Xuc
Thanks for the elaboration. The original post did have much info. Here is a code snippest of test data from AdventureWorks that I mocked up that would work with your issue.
Test Measure =
var _SelectedValueDate = SELECTEDVALUE('FactInternetSales'[OrderDate])
RETURN
CALCULATE(
COUNTROWS('FactInternetSales'),
ALLEXCEPT('FactInternetSales', 'FactInternetSales'[PromotionKey]), //Add any columns here that you're filtering on
'FactInternetSales'[OrderDate] = _SelectedValueDate)
Include any of the columns you're filtering your table on in the ALLEXCEPT function. For instance, in my data I filtered on PromotionKey.
This first screenshot is without including PromotionKey in the ALLEXCEPT, the second screenshot is when it's written to account for the filter.
it does not work, I have adjusted your code to my visual, here is my code:
Sorry if there was confusion, but your code does not match mine. You need to use
ALLEXCEPT('SFX_TRS_RESET_MATURITY_DATES', 'SFX_TRS_RESET_MATURITY_DATES'[FILTERED COLUMN HERE]])
Not ALL('SFX_TRS_RESET_MATURITY_DATES')
If you're filtering on more than one column, separate them with a comma after each column listed.
I am not filtering on more than one column,
I tried the below code, but I get wrong numbers:
yes, exactly, that does not work as a measure because it "refers to an earlier row context which doesn't exist." But I do not need to have it as a calculcated column, if I have it as a column, I get numbers from the ground table (which has more rows than my visual) and not from my visual.
Hi @Shota_Xuc
Try changing EARLIER to MAX.
Hi @gmsamborn MAX does not work either, as you see I get 2 instead of 3 for 2024-02-06, 4 instead of 1 for 2024-02-09, 6 instead of 2 for 2024-02-13 and etc.
@Shota_Xuc , You can try below mentioned measure
Count of Valuation Dates =
COUNTROWS(
FILTER(
'YourTableName',
'YourTableName'[Valuation date] = EARLIER('YourTableName'[Valuation date])
)
)
Please accept as solution and give kudos if it helps
Proud to be a Super User! |
|
That DAX won't work for a measure because it "refers to an earlier row context which doesn't exist."
It would work as a calculated column.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
10 | |
9 | |
8 | |
7 | |
6 |
User | Count |
---|---|
14 | |
13 | |
11 | |
9 | |
8 |