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
Dankang
Regular Visitor

Tricky Dax funcdtion

Display Number weekly.png

 

Hi All

 

Hope anyone can help me with this.

 

Outlet ID refers to stores

Number value refers to the number of displays field reps have built in the store

 

Basially it's assmued that once field reps have built displays the displays they have built will still be up in the store until the next visit. So i want to have the prior week's number of displays if reps don't visit the store in the follwoing weeks.

 

i.e Outlet ID 1000245 although a rep didnt visit the store on the 27th August i want a value of 2 from the prior week and the same number for the follwoing weeks until they visit the store and amend the value again.

 

Then eventually i want a sum of total displays each week.

 

Any advice or help would be greatly appreciated.

 

Cheers

2 REPLIES 2
SteveCampbell
Memorable Member
Memorable Member

The issue is that, I assume, in your data there is actually missing valuesa for the blanks. This is an issue as that means there is actually a nonexistant row.

The *BEST* way, in my opion, would to create a date table. Easiest way is to go to New Table:

 

Date = CALENDARAUTO()

Or, by using Calendar function and passing parameters.

 

 

You can use this Measure:

 

Weekly Count = 
var _date = SELECTEDVALUE('Date'[Date],BLANK())
var _maxDateValue = 
CALCULATE(MAX(Table1[Date])
    ,ALLEXCEPT(Table1,Table1[OutletID])
    ,Table1[Date]<=_date)
    
RETURN
    
CALCULATE(SUM(Table1[Value])
    ,ALLEXCEPT(Table1,Table1[OutletID])
    ,'Date'[Date]=_maxDateValue)

I've highlighted in red names you may need to change as were not available in your question.

 

 

Now, replace your date column in your matrix with 'Date'[Date], and the Value with the new measure Weekly Count.

 

 

 

This will show every day. In order to just show the weeks, you can make a Column in the date table :

 

Include  = 
//checks whether this date is in you original table with data
var _date = 'Date'[Date] return IF(CALCULATE(SUM(Table1[Value]),'Table1'[Date]=_date)>0,1,0)

You can then add this column into the visual level filters, and set as 1.

 

 

 

This is a little more complicated, but lets you apply date logic and date filters. One thing, it will not show total for OutletID. I think in the context of what it is measuring, from my understanding of the question, this makes sense as a sum of a weekly count of outlets would not be relevant (you could just use an AVERAGE function, which would make more sense).

 



Did I answer your question? Mark my post as a solution! Proud to be a Super User!


Connect with me!
Stay up to date on  
Read my blogs on  



Hi @Dankang,

 

Does that make sense? If so, kindly mark the answer as a solution to close the case.

 

Regards,
Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

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.