The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi guys,
I have a table, Table1, with a column of dates, Table1[COMP_DATE]. The dates in Table1[COMP_DATE] can be repetead and they are unsorted.
For each row, I want to calculate how many rows there are in the table with Table1[COMP_DATE] between the date in the row and an year before. Something like:
Table.RowCount(Table1[COMP_DATE]>Table1[COMP_DATE](x)-1 year and Table1[COMP_DATE]<=Table1[COMP_DATE](x)).
any suggestions?
Solved! Go to Solution.
Create a calculated column with the following DAX expression:
CountLastYear =
VAR CurrentDate = Table1[COMP_DATE]
RETURN
COUNTROWS(
FILTER(
Table1,
Table1[COMP_DATE] > EDATE(CurrentDate, -12) &&
Table1[COMP_DATE] <= CurrentDate
)
)
💌 If this helped, a Kudos 👍 or Solution mark would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn
Create a calculated column with the following DAX expression:
CountLastYear =
VAR CurrentDate = Table1[COMP_DATE]
RETURN
COUNTROWS(
FILTER(
Table1,
Table1[COMP_DATE] > EDATE(CurrentDate, -12) &&
Table1[COMP_DATE] <= CurrentDate
)
)
💌 If this helped, a Kudos 👍 or Solution mark would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn
It works. But I have a prolem. I need to filter to select a date in a slicer, so i need to remove that filters and still had to work
Hello @SebaSpotti,
Can you please try the following approach:
RowsInLastYear =
VAR CurrentDate = Table1[COMP_DATE]
RETURN
COUNTROWS(
FILTER(
Table1,
Table1[COMP_DATE] > (CurrentDate - 365) &&
Table1[COMP_DATE] <= CurrentDate
)
)
Hope this helps.
It works. But I have a prolem. I need to filter to select a date in a slicer, so i need to remove that filters and still had to work
Hi @SebaSpotti ,
Could you add more details on where you're stuck now? From the discussion above you now get a new calculated column, what is your expected output next?
Best Regards,
Gao
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data in the Power BI Forum
User | Count |
---|---|
78 | |
77 | |
36 | |
32 | |
29 |
User | Count |
---|---|
91 | |
79 | |
57 | |
48 | |
48 |