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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Syndicate_Admin
Administrator
Administrator

Get previous month's sales of products that have sales on the current and total date

As the title says I want to filter in some way the sales of the previous month that I get with this formula:

Advance LM < =
CALCULATE([Advance],DATEADD(Calendar[Date],-1, MONTH))

And only show sales from the previous month when they have sales in the current period. Some told me but condition if it is blank then do not put anything, if that can work when it is separated by category. But when they are grouped, the conditional does not work:
Epuma_0-1633110492235.png




I am using as an example only one day I leave you a test pbix that I put together to try to perform the measurement.

Epuma_1-1633110492029.png


They helped me with a measure but the total is adding another value:

Measure = SUMX(FILTER(VALUES('data tests'[DISTRIBUTOR]),[Advance]>0),[LM Advance <])




I work well at the level records this formula but to show every day is not correctly adding the value, I was thinking of using a hasonevalue but it would not be the solution since this measure will be used in many ways and you would have to create many hasonvalue :

Epuma_2-1633110554963.png


PBix :
https://we.tl/t-yt3K2nJCNz

1 ACCEPTED SOLUTION

Try combining your measurements :

AK Avance LM < DAILY = SUMX(Calendar, IF([Advance] <> BLANK(), [LM Advance < v2]))

And it worked:

Epuma_0-1633369950667.png

Now I will try it on the original pbix.

View solution in original post

3 REPLIES 3
AllisonKennedy
Super User
Super User

@Epuma  Thanks for starting another post - your other message was getting busy I guess so some replies have been lost in the thread! (ref to your other post for benefit of other users: https://community.powerbi.com/t5/Desktop/Get-previous-month-s-sales-of-products-that-have-sales-on-t...

 

How do you define 'Period'? Your question is all about the DAX Context you provide to your measure. You need to provide the context of the period, but you're providing the context of the Distribuidor. You need to use Calendario in your SUMX. You do not need to use VALUES(distribuidor). 


Please see both pages of my update of your file, and also these measures: 

 

Using Day as the Period

(so use the Calendario table as the context for your SUMX measure): 

 

AK Avance LM < DAILY = SUMX(Calendario, IF([Avance] <> BLANK(), CALCULATE([Avance], DATEADD(Calendario[Date], -1 , MONTH))))

 

Using Month, Year as the Period

I have used the VALUES(Calendario[Ano Mes]) column as the context for SUMX measure, but you could use Calendario[Periodo] with the same result: 

AK Avance LM < MONTHLY = 
SUMX(VALUES(Calendario[Año Mes]), CALCULATE([Avance], DATEADD(Calendario[Date], -1, MONTH)))

 

Output:

Check both pages of your attached report (see below signature). Pagina 1 is filtered for 2021-9 Periodo and Duplicate of Pagina 1 has no filter for Period.

AllisonKennedy_0-1633137234660.png

 


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Thank you very much for replying, but I need the total to show the sum of the results in Avance LM < v2 :

Epuma_1-1633368445126.png

The correct total is: 1066152

Epuma_2-1633368486849.png

Try combining your measurements :

AK Avance LM < DAILY = SUMX(Calendar, IF([Advance] <> BLANK(), [LM Advance < v2]))

And it worked:

Epuma_0-1633369950667.png

Now I will try it on the original pbix.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.