Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
I have a table which is essentially like the one below. Each time one gives us a "Sentiment" of Positive/Neutral/Negative/Unclassified that sentiment is added as a new line, along with the date.
I have dates that go back to the start of the year so I want to record how many of each category have been recorded over the previous 30 days (including the day in question), so I can produce 100% stacked chart like this:
So I created this measure:
Sentiment MMT =
CALCULATE(
Count(Sentiment[Sentiment]),
DATESINPERIOD(
'Sentiment'[Date],
MAX('Sentiment'[Date]),
-1,MONTH
)
)
The problem I'm having is that if on one of the days it happens that no-one recorded a particular sentiment, then rather than counting up all entries for the other 29 days, it just returns a blank – you can see wome exmaples in the bottom right where there are no grey values.
An example of the data (which doesn't correspond precisely to the chart , it's just to give you an idea) is below.
Does anyone have any ideas?
Date | Sentiment |
30-Apr-23 | Neutral |
30-Apr-23 | Positive |
30-Apr-23 | Unclassified |
30-Apr-23 | Positive |
29-Apr-23 | Neutral |
29-Apr-23 | Neutral |
29-Apr-23 | Neutral |
29-Apr-23 | Neutral |
29-Apr-23 | Neutral |
29-Apr-23 | Neutral |
29-Apr-23 | Positive |
29-Apr-23 | Positive |
29-Apr-23 | Positive |
29-Apr-23 | Positive |
29-Apr-23 | Neutral |
29-Apr-23 | Neutral |
29-Apr-23 | Neutral |
29-Apr-23 | Positive |
29-Apr-23 | Positive |
etc.
Solved! Go to Solution.
@Coriel-11
Create a DATES table, Link the dates table to your fast table using a one-to-many relation and modify your calculation. Make sure you use the Date column from your Dates table in the Visual. Create a Copy of the Dates table for date selection as well.
Here is the modified formula:
Sentiment MMT =
VAR __DateSelected = SELECTEDVALUE('Date Selector'[Date])
VAR __CurrentDate = SELECTEDVALUE('Dates'[Date])
VAR __Period =
DATESINPERIOD(
'Dates'[Date],
__CurrentDate,
1,
MONTH
)
Return
IF(
__DateSelected IN __Period,
CALCULATE(
Count(Sentiment[Sentiment]),
__Period
)
)
File is attached
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
@Coriel-11
Create a DATES table, Link the dates table to your fast table using a one-to-many relation and modify your calculation. Make sure you use the Date column from your Dates table in the Visual. Create a Copy of the Dates table for date selection as well.
Here is the modified formula:
Sentiment MMT =
VAR __DateSelected = SELECTEDVALUE('Date Selector'[Date])
VAR __CurrentDate = SELECTEDVALUE('Dates'[Date])
VAR __Period =
DATESINPERIOD(
'Dates'[Date],
__CurrentDate,
1,
MONTH
)
Return
IF(
__DateSelected IN __Period,
CALCULATE(
Count(Sentiment[Sentiment]),
__Period
)
)
File is attached
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
Thank you!!. I had tried that, but for some reason I hadn't added the date table date to the visual's X axis, so I'd disregarded that approach and gone back to trying to do something more Dax-y.
Much appreciated. It was driving me mad!
Matt
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 |
---|---|
16 | |
13 | |
12 | |
11 | |
11 |
User | Count |
---|---|
19 | |
14 | |
14 | |
11 | |
9 |