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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Dax column to show last 4 weeks

I have a table that looks as follows:

 

Load                         Count

8/11/2019                   4673

8/18/2019                  3442

8/25/2019                  2334

9/1/2019                    4224

9/8/2019                    9472

 

(Load - All sundays/ weekly data)

At any point, I would like the report to show only the latest 4 weeks of data (in this case 8/18, 8/25, 9/1, 9/8) .. and another example is, next week (8/25, 9/1, 9/8, 9/15) 

 

Maybe a Dax that gives me "Last 4 weeks - Yes/NO" so that i can set the page level filter to Yes. Can this be done? Thank you!

2 ACCEPTED SOLUTIONS

@Anonymous please try this

Rank = RANKX('Table','Table'[Load],,DESC,DENSE)
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

dax
Community Support
Community Support

Hi Akshaya, 

You could create a slicer table like below

341.PNG

Then create a measure like below

Measure 6 =
SWITCH (
    TRUE (),
    SELECTEDVALUE ( 'slicer'[slicer] ) = "next week", CALCULATE (
        SUM ( 'month'[count] ),
        FILTER (
            'month',
            WEEKNUM ( 'month'[Load] )
                >= WEEKNUM ( TODAY () ) - 3
                && WEEKNUM ( 'month'[Load] )
                    <= WEEKNUM ( TODAY () ) + 1
        )
    ),
    SELECTEDVALUE ( 'slicer'[slicer] ) = "last4week", CALCULATE (
        SUM ( 'month'[count] ),
        FILTER (
            'month',
            WEEKNUM ( 'month'[Load] )
                >= WEEKNUM ( TODAY () ) - 4
                && WEEKNUM ( 'month'[Load] ) <= WEEKNUM ( TODAY () )
        )
    )
)

342.PNG

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
dax
Community Support
Community Support

Hi Akshaya, 

You could create a slicer table like below

341.PNG

Then create a measure like below

Measure 6 =
SWITCH (
    TRUE (),
    SELECTEDVALUE ( 'slicer'[slicer] ) = "next week", CALCULATE (
        SUM ( 'month'[count] ),
        FILTER (
            'month',
            WEEKNUM ( 'month'[Load] )
                >= WEEKNUM ( TODAY () ) - 3
                && WEEKNUM ( 'month'[Load] )
                    <= WEEKNUM ( TODAY () ) + 1
        )
    ),
    SELECTEDVALUE ( 'slicer'[slicer] ) = "last4week", CALCULATE (
        SUM ( 'month'[count] ),
        FILTER (
            'month',
            WEEKNUM ( 'month'[Load] )
                >= WEEKNUM ( TODAY () ) - 4
                && WEEKNUM ( 'month'[Load] ) <= WEEKNUM ( TODAY () )
        )
    )
)

342.PNG

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

sy898661
Helper V
Helper V

Try this:

=    IF(
        [Load] >= TODAY() - 30,
        "Y",
        BLANK()
    )
And then you can filter Y!
🙂
smpa01
Super User
Super User

@Anonymous  one way of doing that would be through calculated columns as following

Rank = RANKX('Table','Table'[Load],,DESC)

and always put filter from 1-4

 

1e.PNG

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Anonymous
Not applicable

Week Ranking.png 

@smpa01  This is the output i am getting. Week Rank is a calculated column (Dont Summarize enabled)

@Anonymous please try this

Rank = RANKX('Table','Table'[Load],,DESC,DENSE)
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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