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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
jayasurya_prud
Helper II
Helper II

How to get 10 days - Dates as columns in Matrix value based on slicer selection

I am working on a task where I have created a matrix and slicer

 

matrix 

 

rows - category

columns - calendar[date] column

values - distinct count of key

 

jayasurya_prud_0-1737070764179.png

 

now the problem i am trying to solve is 

 

based on the date selected in slicer, my matrix columns should display only the slicer seleced date and prior dates columns 

 

if I select 2/12/2023

 

 i need to see columns only from 2/2/2023 to 2/12/2023

 

how to get this?

 

I tried many ways creating calendar table

 

using measure in visual level filter by selecteddate, min and mox date, daterange, crossfilter, keepfilter, treatas, all, and many

 

but not getting to the solution

 

main problem is based on the date i select on slicer I only get one column (ex: If I select 2/12/2023, I only get one col). But i dont want that. Based on the date I select in slicer I need the prior days in matrix columns too. 

 

the most close approach I tried is to create a measure 

Distinct Visit Count =

VAR SelectedDate = SELECTEDVALUE('Table'[Date])
VAR MinDate = SelectedDate - 29
VAR MaxDate = SelectedDate

VAR IsInRange =
    MAX('Calendar'[Date]) >= MinDate &&
    MAX('Calendar'[Date]) <= MaxDate

VAR Calc =
        CALCULATE(
            DISTINCTCOUNT('table'[Key])
       , 'Table'[Date] >= MinDate &&
         'table'[Date] <= MaxDate
        )
 

RETURN
    IF(ISBLANK(Calc), 0, Calc)


and use this mesure in values of matrix

If i use this, I am getting all the date columns but vlues pooping only for the slicer date selected and remaining all columns as 0

 

jayasurya_prud_1-1737071268949.png



how to get the solution

 

@amitchandak 

@hackcrr 

@v-kmc 

@v-cyu 

@v-jingzhang 

@v-jiewu-msft 

@v-jianpeng-msft 

@v-nuoc-msft 

 

and #superusers

 

2 ACCEPTED SOLUTIONS
Ashish_Mathur
Super User
Super User

Hi,

I have solved a similar question in the attached file.

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

Uzi2019
Super User
Super User

Hi @jayasurya_prud 

 

create Column then write this

AverageRate =
VAR currentDate = 'Table1'[Date]
VAR startDate = currentDate - 9
RETURN
    IF (
        MIN ( 'Table1'[Date] ) > startDate,
        BLANK (),
        CALCULATE (
            DISTINCTCOUNT ( Table1[Rate] ),
            FILTER (
                ALL ( 'Table1' ),
                'Table1'[Date] <= currentDate
                    && 'Table1'[Date] >= startDate
            )
        )
    )

 

I hope I answered your question! 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

View solution in original post

3 REPLIES 3
Uzi2019
Super User
Super User

Hi @jayasurya_prud 

 

create Column then write this

AverageRate =
VAR currentDate = 'Table1'[Date]
VAR startDate = currentDate - 9
RETURN
    IF (
        MIN ( 'Table1'[Date] ) > startDate,
        BLANK (),
        CALCULATE (
            DISTINCTCOUNT ( Table1[Rate] ),
            FILTER (
                ALL ( 'Table1' ),
                'Table1'[Date] <= currentDate
                    && 'Table1'[Date] >= startDate
            )
        )
    )

 

I hope I answered your question! 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Hi @jayasurya_prud 

 

you can use same logic of this video instead of month you can change it to 10 days.

 

https://www.youtube.com/watch?v=duMSovyosXE&t=76s

 

I hope I answered your question!

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!
Ashish_Mathur
Super User
Super User

Hi,

I have solved a similar question in the attached file.

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

Find out what's new and trending in the Fabric community.