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
adityavighne
Continued Contributor
Continued Contributor

Previous week distinct count - Dynamic date range between-slicer

Hello All,

 

I want to use Slicer - Between the date range

date slicer.PNG

I need to calculate data - the table shows Distinct count of the selected date range 25-31 JAN 2019 and the next column shows the previous 7 days data - 18-24 JAN 2019

 

So I need selected week 25-31 and previous week 18-24 also this date range changes as per selection and calculation for a previous week also.

Week.PNG

 

Kindly help with this.

8 REPLIES 8
v-qiuyu-msft
Community Support
Community Support

Hi @adityavighne ,

 

You can create measures below: 

 

SelectedCount = CALCULATE(DISTINCTCOUNT('Table1'[ID]),ALLSELECTED(Table1[Date]))
 
PrevCount = var StartDate=CALCULATE(MIN('Table1'[Date]),ALLSELECTED(Table1[Date]))
return
CALCULATE(DISTINCTCOUNT(Table1[ID]),FILTER(ALL('Table1'),'Table1'[Date]<StartDate && 'Table1'[Date]>=StartDate-7))
 
q1.PNG
 
Best Regards,
Qiuyun Yu 
Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi,

 

Thanks for the reply.

 

still, this measure giving me the same values for all. I don't know why. do you have a solution for this?

Capture.PNG

Your answer is giving data of 25th which is 13. I don't want the previous 7th-day value.

 

I want to distinct count of all previous 7 days, on basis of date selection.

 

you can replicate this same data multiple time.

 

DateIDPage
1/1/2019197190032317476_8447973776680082058
1/2/2019197190032317476_8447973776680082058b
1/3/2019197190032317476_8447973776680082058c
1/4/2019197190032317476_8447973776680082058d
1/5/2019197190032317476_8447973776680082058
1/6/2019197190032317476_8447973776680082058b
1/7/2019197190032317476_8447973776680082058c
1/8/2019197190032317476_8447973776680082058d
1/9/2019197190032317476_8447973776680082058
1/10/2019197190032317476_8447973776680082058b
1/1/2019197190032317476_8447973776680082058c
1/2/2019197190032317476_8447973776680082058d
1/3/2019197190032317476_8447973776680082058
1/4/2019197190032317476_8447973776680082058b
1/5/2019197190032317476_8447973776680082058c
1/6/2019197190032317476_8447973776680082058d
1/7/2019197190032317476_8447973776680082058
1/8/2019197190032317476_8447973776680082058b
1/9/2019197190032317476_8447973776680082058c
1/10/2019197190032317476_8447973776680082058d
1/21/2019197190032317476_8447973776680082058
1/22/2019240206843928821_6961211759885737083b
1/23/2019601038483776190_7735836360593054066c
1/24/2019601038483776190_7735836360593054066d
1/25/2019871268945591513_7132526101485594407
1/26/2019871268945591513_7132526101485594407b
1/27/2019871268945591513_7132526101485594407c
1/28/2019924367417028370_7492928701214981402d
1/29/2019924367417028370_7492928701214981402
1/30/2019976458848054501_9150205732877128846b
1/31/2019111595305812628_3947417046463777469c
2/1/2019111595305812628_3947417046463777469d
2/2/2019111595305812628_3947417046463777469
2/3/2019111595305812628_3947417046463777469b
2/4/2019111595305812628_3947417046463777469c
2/5/2019111595305812628_3947417046463777469d
2/6/2019111595305812628_3947417046463777469
2/7/2019456312410448513_1803518541748429750b
2/8/2019561338730605101_2524091600258641980c
2/9/2019975908977245798_2575588146540217511d
2/10/2019561338730605101_2524091600258641980
2/11/2019813030921949569_6731309020712374740b
1/31/2019813030921949569_6731309020712374740c
2/1/201991525604482_6917529027642678403d
2/2/201991525604482_6917529027642678404
2/3/2019210411206300380_3783820045567045205b
2/4/2019236366378936516_3199577556528193066c
2/5/2019236366378936516_3199577556528193066d
2/6/201928032831195_4611686018428362112
2/7/2019313719516475327_976193923802676546b
2/8/2019325905515714656_8464730794280148558c
2/9/2019325905515714656_8464730794280148558d
2/22/2019325905515714656_8464730794280148558
2/23/2019511737054629859_8887502822576098568b
2/24/2019511737054629859_8887502822576098568c
2/25/2019511737054629859_8887502822576098568d
2/26/2019719420328982500_6255106219615310759
2/27/2019757808328588592_6576602539323115301b
2/28/201996009959044646_8585768053587895667c
3/1/2019975908977245798_2575588146540217511d
3/2/2019975908977245798_2575588146540217511
3/3/2019113415991117440_4972186124049347874b
3/4/2019128634539808414_319656911601974419c
3/5/2019128634539808414_319656911601974419d
3/6/2019128634539808414_319656911601974419
3/7/2019128634539808414_319656911601974419b
3/8/2019128634539808414_319656911601974419c
3/9/2019128634539808414_319656911601974419d
3/10/2019128634539808414_319656911601974419
3/11/2019128634539808414_319656911601974419b
3/12/2019128634539808414_319656911601974419c
3/13/2019128634539808414_319656911601974419d
3/1/2019128634539808414_319656911601974419
3/2/2019128634539808414_319656911601974419b
3/3/2019128634539808414_319656911601974419c
3/4/2019196764414215809_8223654677792577539d
3/5/2019196764414215809_8223654677792577539
3/6/201922522112668_6917529027641685833b
3/7/201922522112668_6917529027641685834c
3/8/2019272813184619803_8956493669860760235d
3/9/201928964562651_4611686018428362215
3/23/201928964562651_4611686018428362216b
3/24/2019438768319479192_3580915507711873005c
3/25/2019500455146427302_680677433280831741d
3/26/201965471778655_4611686018428940550
3/27/201965471778655_4611686018428940551b
3/28/2019671782382512216_3343211043005839716c
3/29/2019826862339174853_6257497371105885372d
3/30/201989094099998_4611686018429742527
3/31/2019064878666113544_3397210365041580786b
4/1/2019064878666113544_3397210365041580786c
4/2/2019433093231140311_2535359322293741002d
4/3/2019433093231140311_2535359322293741002
4/4/2019433093231140311_2535359322293741002b
4/5/2019433093231140311_2535359322293741002c
4/6/2019433093231140311_2535359322293741002d
4/7/2019433093231140311_2535359322293741002
4/8/2019433093231140311_2535359322293741002b
4/9/2019433093231140311_2535359322293741002c
4/10/2019433093231140311_2535359322293741002d
4/11/201951371130587_4611686018428362315
4/12/201951371130587_4611686018428362316b
4/13/2019663033245042090_1392993905040621870c
4/14/2019663033245042090_1392993905040621870d
4/15/2019663033245042090_1392993905040621870
4/16/2019756118180281553_6003012718445353881b
4/17/2019865578752531610_7910682634347150233c
4/18/2019865578752531610_7910682634347150233d
4/19/201994320791915_6917529027641425995
4/20/201994320791915_6917529027641425996b
4/21/201925484284832355_4454362085951793166c
4/22/201925484284832355_4454362085951793166d
4/23/2019585684800584734_8529241723173736215
4/24/2019612375618501819_7236046624097960175b
4/9/2019612375618501819_7236046624097960175c
4/10/2019612375618501819_7236046624097960175d

 

Output required - 

Capture1.PNG

Hi @adityavighne

 

Which filter do you use? I see you use PowerPivot table as a sample, I would suggest you use Power BI desktop to share how you use filters to decide selected week so I can go further to test. 

 

Best Regards,
Qiuyun Yu 

Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

I'm trying to achieve the result like below screenshot in a table, not separate tables.

 

Capture2.PNG

 

 

Can someone help with this? 

Hi @adityavighne,

 

You can create a measure below: 

 

PreWeekCount = var StartDate=CALCULATE(MIN('Table1'[Date]),ALLSELECTED(Table1))
var EndDate=CALCULATE(Max('Table1'[Date]),ALLSELECTED(Table1))
return IF(ISINSCOPE(Table1[Page]),CALCULATE(DISTINCTCOUNT(Table1[ID]),FILTER(ALL('Table1'),'Table1'[Date]>=StartDate-7 && Table1[Date]<=EndDate-7&&Table1[Page]=MAX(Table1[Page]))),CALCULATE(DISTINCTCOUNT(Table1[ID]),FILTER(ALL(Table1),'Table1'[Date]>=StartDate-7 && Table1[Date]<=EndDate-7)))
 
q1.PNGq2.PNG
 
 
Best Regards,
Qiuyun Yu 
Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks for the reply.

 

This measure is taking too much time to load the data. Still, I don't see any result.

 

I think something else needs to try for a change in above DAX

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.