Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Coriel-11
Resolver I
Resolver I

Total for last 30 days when no entries for particular dates

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:

Coriel11_0-1683301924826.png

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?

 

DateSentiment
30-Apr-23Neutral
30-Apr-23Positive
30-Apr-23Unclassified
30-Apr-23Positive
29-Apr-23Neutral
29-Apr-23Neutral
29-Apr-23Neutral
29-Apr-23Neutral
29-Apr-23Neutral
29-Apr-23Neutral
29-Apr-23Positive
29-Apr-23Positive
29-Apr-23Positive
29-Apr-23Positive
29-Apr-23Neutral
29-Apr-23Neutral
29-Apr-23Neutral
29-Apr-23Positive
29-Apr-23Positive

etc.

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@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 
    )
)

Fowmy_0-1683322883444.png

 

 File is attached

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

2 REPLIES 2
Fowmy
Super User
Super User

@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 
    )
)

Fowmy_0-1683322883444.png

 

 File is attached

Did I answer your question? Mark my post as a solution! and hit thumbs up


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

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Top Kudoed Authors