March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hi,
When use a table or similar visual, is it possible to list the items with metrics those have 3 weeks consecutive changes? either growth or decline. Here is the sample file: sample excel file
E.g. in the 1st table (by URL):
When user selects Week "17", expect table list the Yellow highlighted one as "3 weeks consecutive decline".
When user selects Week "17", expect table list the Red font items from week 15 to 17 as "3 weeks consecutive growth".
When user selects Week "16", expect table list the the orange highlighted one as "3 weeks consecutive decline".
When user selects Week "16", expect table list the Red font items from week 14 to 16 as "3 weeks consecutive growth".
Same logic to the 2nd table (by Query).
sample excel file (same to the beginning one)
Raw data as screen capture.
Additional Topic:
Is it possible to allow user to select "how many consecutive weeks want to be checked".
When user input 3 / 4 / 5, then, identify the data 3 / 4 / 5 Weeks before the current selected week.
Thanks in advance.
Solved! Go to Solution.
Hi again @h_l
Attached is a sample PBIX illustrating what I hope is close to what you're wanting 🙂
When interpreting your requirements, I took it that "3 consecutive weeks of increase" as at week 17 means weeks 15, 16 and 17 form an increasing sequence, i.e. we can ignore the movement from week 14 to 15.
The end result looks like this:
There were a few steps I followed to get this working. I won't list all of the DAX here as it is a bit longwinded and you can see it in the PBIX 🙂
Display Date Range =
VAR ConsWeeks =
SELECTEDVALUE ( 'Consecutive Weeks'[Consecutive Weeks] )
VAR DateRangeMax =
MAX ( 'Reference Date'[Reference Date] )
VAR DateRange =
DATESINPERIOD ( 'Date'[Date], DateRangeMax, -ConsWeeks * 7, DAY )
VAR InDateRange =
CALCULATE (
NOT ISEMPTY ( 'Date' ),
KEEPFILTERS ( DateRange )
)
RETURN
InDateRange
Impressions Segmented by URL =
VAR ItemsInSegment =
FILTER (
ALLSELECTED ( Metrics[URL] ),
VAR DirectionOfCurrentItem = [Direction Type]
VAR SegmentForCurrentItem =
FILTER (
'Impressions Segments',
'Impressions Segments'[Direction] = DirectionOfCurrentItem
)
VAR InSegment = NOT ISEMPTY ( SegmentForCurrentItem )
RETURN InSegment
)
VAR Result =
CALCULATE (
[Impressions],
KEEPFILTERS ( ItemsInSegment ) -- Applies filter for segmented customers
)
RETURN Result
Hopefully that's useful, and you can tweak to suit your exact needs.
All the best!
Owen
This is an very nice en powerfull script. I changed it to an Excel version and changed the dax code a little bit. But I have some questions. I am unable to change this myself.
- When I choose 2 years, but er isn't data available for the 2 years, is it possible to not show that casename.
- When I choose some years and all the years are the same numbers, that is than increased (or the same) and not mixed.
- When I choose 3 years and there is data available for 2 years (and for 1 year not), calculated then based on the 2 available years.
In the file I have some examples which what is my meaning.
Excel file:
https://www.filemail.com/d/gjvwzenthhbariw
Hi again @h_l
Attached is a sample PBIX illustrating what I hope is close to what you're wanting 🙂
When interpreting your requirements, I took it that "3 consecutive weeks of increase" as at week 17 means weeks 15, 16 and 17 form an increasing sequence, i.e. we can ignore the movement from week 14 to 15.
The end result looks like this:
There were a few steps I followed to get this working. I won't list all of the DAX here as it is a bit longwinded and you can see it in the PBIX 🙂
Display Date Range =
VAR ConsWeeks =
SELECTEDVALUE ( 'Consecutive Weeks'[Consecutive Weeks] )
VAR DateRangeMax =
MAX ( 'Reference Date'[Reference Date] )
VAR DateRange =
DATESINPERIOD ( 'Date'[Date], DateRangeMax, -ConsWeeks * 7, DAY )
VAR InDateRange =
CALCULATE (
NOT ISEMPTY ( 'Date' ),
KEEPFILTERS ( DateRange )
)
RETURN
InDateRange
Impressions Segmented by URL =
VAR ItemsInSegment =
FILTER (
ALLSELECTED ( Metrics[URL] ),
VAR DirectionOfCurrentItem = [Direction Type]
VAR SegmentForCurrentItem =
FILTER (
'Impressions Segments',
'Impressions Segments'[Direction] = DirectionOfCurrentItem
)
VAR InSegment = NOT ISEMPTY ( SegmentForCurrentItem )
RETURN InSegment
)
VAR Result =
CALCULATE (
[Impressions],
KEEPFILTERS ( ItemsInSegment ) -- Applies filter for segmented customers
)
RETURN Result
Hopefully that's useful, and you can tweak to suit your exact needs.
All the best!
Owen
Hi @OwenAuger ,
May I come back and ask:
When I load 2022 data into the DB, seems the function does not work well. (When I test in 2021 use 2021 data, everything works well.)
Take 2 examples:
I tried to investigate the reason but so far still not be able to find the way to "debug".
Would you mind to provide an idea?
Have a safe and joyful day.
Hi @h_l
Good to hear from you again 🙂
The calculation logic should work, but there could be something going on with how the tables have been rolled forward to the next year.
You could double-check that 'Date' and 'Reference Date' have been correctly extended into 2022, and the Week Index column should contain a unique index for each week.
Also, for the Columns of the matrix visuals, perhaps use a Year-Week column rather than just Week Index. Or include both Year and Week in Columns.
If you can post a sanitised PBIX (or DM me), I may be able to offer some better suggestions.
Regards,
Owen
Hi @OwenAuger ,
Appreciate your reply and sorry for this so late post...I was struggling in traveling and related matters.
I will look into follow by your advise, and may come back or send message to you if there is further questions.
I hope you have safe and joyful days.
Thanks again!
Hi Owen,
just come back to let you know that the solution is working well.
Thanks again!
H
Hi @OwenAuger , first of all, please accept my sincere appreciation to your time and great effort to help, so I come to reply you at the first second I see your reply.
Per your interpreting to:
I took it that "3 consecutive weeks of increase" as at week 17 means weeks 15, 16 and 17 form an increasing sequence, i.e. we can ignore the movement from week 14 to 15.
- It is correct, as week 17 is selected, then the increase from week 14 to 15 can be ignored. But when Week 16 is selected, then Week 14-15-16 shall be identified and listed.
As the solution is a little complicate to me, I will take sometime to investigate and understand it. Will come back and let you know the result.
Thanks again for your time, have a good day!
Best,
H
Hi @h_l
Something like a Dynamic Segmentation pattern will work here (see this page on DAX Patterns for the general idea).
Normally that involves creating a disconnected segmentation table. In your case, the segments could be something like "Consecutive growth", "Consecutive decline" and "Other", with the number of weeks input via a separate parameter slicer.
I can provide some suggested measures, but probably best to do using your actual data.
The link to your Excel file leads to a "file deleted" page. Could you re-upload?
Regards,
Owen
Hi Owen,
Thanks for your reply and clarification, I also checked some posts in this great community with super help users like you, but seems they didn't really meet this scenario.
Here is the updated sample data link.
Will check the page you referred later.
Have a good day!
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
123 | |
85 | |
85 | |
70 | |
51 |
User | Count |
---|---|
205 | |
153 | |
97 | |
79 | |
69 |