cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
EddyBA
Regular Visitor

Previous period measure (no date)

Hi community,

 

I would like to create one simple measure for previous period revenue without using "date" field. So I have created an index for each update I will do (every week). I will use a slicer on the index/week, so if i select week 2, prior should show week 1 figures.

 

I have several rows so I am using the following formula to calculate "Sales Period" :

Sales Period = SUMX(FILTER(Sheet1, MAX(Sheet1[index])),Sheet1[sales])

 

How can we calculate "Sales Prior" ? I've tried the following DAX but it's not working :S

Sales Prior = SUMX(FILTER(Sheet1, MAX(Sheet1[index])-1),Sheet1[sales])

 

IndexWeekSalesSales PeriodSales Prior
1week 150  
1week 1100  
2week 22020150
3week 3303020
     

 

Thank you in advance for any suggestions/advices.

1 ACCEPTED SOLUTION
v-xiaotang
Community Support
Community Support

Hi @EddyBA 

You need to create an independent Week table, 

weekslicer = VALUES('Table'[Index])

 

 

vxiaotang_2-1643267831093.png

then create the measures bellow,

test1 = CALCULATE(SUM('Table'[Sales]),ALLEXCEPT('Table','Table'[Week]))
test2 =
VAR _week =
    SELECTEDVALUE ( weekslicer[Index] ) - 1
VAR _valuePrior =
    CALCULATE (
        SUM ( 'Table'[Sales] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Index] = _week )
    )
RETURN
    IF (
        MIN ( 'Table'[Index] ) = SELECTEDVALUE ( weekslicer[Index] ),
        _valuePrior,
        BLANK ()
    )

vxiaotang_0-1643267789559.pngvxiaotang_1-1643267799831.png

Best Regards,

Community Support Team _Tang

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

View solution in original post

4 REPLIES 4
v-xiaotang
Community Support
Community Support

Hi @EddyBA 

You need to create an independent Week table, 

weekslicer = VALUES('Table'[Index])

 

 

vxiaotang_2-1643267831093.png

then create the measures bellow,

test1 = CALCULATE(SUM('Table'[Sales]),ALLEXCEPT('Table','Table'[Week]))
test2 =
VAR _week =
    SELECTEDVALUE ( weekslicer[Index] ) - 1
VAR _valuePrior =
    CALCULATE (
        SUM ( 'Table'[Sales] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Index] = _week )
    )
RETURN
    IF (
        MIN ( 'Table'[Index] ) = SELECTEDVALUE ( weekslicer[Index] ),
        _valuePrior,
        BLANK ()
    )

vxiaotang_0-1643267789559.pngvxiaotang_1-1643267799831.png

Best Regards,

Community Support Team _Tang

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

ValtteriN
Super User
Super User

Hi,

Have a look at EARLIER function: 

https://docs.microsoft.com/fi-fi/dax/earlier-function-dax

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thank you ValtteriN,

I have already tried this function but unfortunately it's not working.

 

Hi,

Another option that comes to my mind besides utilizing EARLIER is separating weeknum into its own column and using that in the calculation. e.g.

[earlierWeekSales] =
var _week = MAX(calendar[weeknum])
var _latestweek = CALCULATE(MAX(Table[weeknum]),ALL(calendar),table[weeknum]<_week)
return
CALCULATE(SUM(table[value]),ALL(calendar),table[weeknum]=_latestweek)

Edit: you might need to add years to the calculate, but the basic logic is the same





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

MPPC 2023 PBI Carousel

Power Platform Conference-Power BI and Fabric Sessions

Join us Oct 1 - 6 in Las Vegas for the Microsoft Power Platform Conference.

Top Solution Authors
Top Kudoed Authors