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
cosminc
Post Partisan
Post Partisan

comparing last month, previous and last month-12 (same month previous year) -DAX

Hi

i need to buid a graph top salesman rox and legend month - and need to be fixed with max month, max month-1 and max month-12,

i use a calendar (1 jan 2017 till 31 dec 2019) connected with the data base

 

let's take a simple example

salesman    sales  year  month

 

 
thanks!
Cosmin
10 REPLIES 10
Greg_Deckler
Super User
Super User

See if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi Greg,

i didn't find what i need 

if you have 2 minutes it would be very helpful for me, i'm stuck on this

 

i want to built a measure like this:

Month Comparison =
VAR MaxYear = CALCULATE(MAX(Source[Year]), ALL(Source))
VAR MaxMonthNr = CALCULATE(MAX(Source[Year Month Number]), Source[Year] <= MaxYear)
RETURN
CALCULATE(SUM(Source[Sales), FILTER(Source, Source[Year Month Number] = MaxMonthNr && MaxMonthNr -1 && MaxMonthNr -12))
 
i need to make a fixed graph (without filters, but updatable with new data) with top 10 salesmen (as example) after sales from MaxMonthNr (last month with data), but also i need to put on graph previous month and same month last year for comparisons
so a need t put on bar graph - Salesmen - axis, the measure from above as Legend and Sales on Value.
 
More than that a need a measure to filter top 10 salesmen after Sales from MaxMonthNr not top 10 after all 3 months.
 
i also have a calendar but on this situation i think is not proper to use it, there last month is december 2019 not february 2019 like on my data base.
 
help me please with the right syntaxes
Thanks a lot!
Cosmin 

Hi,

 

Show a sample dataset and also the expected result.  Just show your expected result in a Table format.  From there, we can always change the visual to a graph.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi,

 

Data series, objectives and expected result are put below:

if it's helpfull i use a calendar till 31-12-2019 in relationship with the data base

thanks a lot!

Cosmin 

 

YearMonthNoSalesmanSales
20192George59
20191George68
20181George71
20182George94
20183George89
20184George83
20185George53
20186George91
20187George83
20188George51
20189George78
201810George64
201811George88
201812George99
20171George97
20172George93
20173George100
20174George82
20175George92
20176George65
20177George90
20178George52
20179George99
201710George80
201711George67
201712George95
20191Alex59
20181Alex86
20182Alex50
20183Alex65
20184Alex79
20185Alex63
20186Alex94
20187Alex97
20188Alex96
20189Alex98
201810Alex97
201811Alex80
201812Alex92
20171Alex87
20172Alex79
20173Alex57
20174Alex61
20175Alex88
20176Alex77
20177Alex62
20178Alex78
20179Alex60
201710Alex55
201711Alex63
201712Alex57
20182Teo88
20183Teo56
20184Teo85
20185Teo80
20186Teo86
20187Teo73
20188Teo51
20189Teo67
20192Jenna93
20191Jenna63
20181Jenna100
20182Jenna78
20183Jenna73
20184Jenna73
20185Jenna74
20186Jenna58
20187Jenna93
20188Jenna97
20189Jenna100
201810Jenna59
201811Jenna84
201812Jenna78
20171Jenna84
20172Jenna66
20173Aimee72
20174Aimee77
20175Aimee53
20176Aimee98
20177Aimee99
20178Aimee98
20179Aimee80
201710Aimee60
201711Aimee58
201712Aimee92
20191Aimee59
20181Aimee86
20182Aimee63
20183Jason61
20184Jason94
20185Jason86
20186Jason53
20187Jason81
20188Jason94
20189Jason51
201810Jason70
201811Jason52
201812Jason91
20171Jason73
20172Jason62
20173Jason65
20174Jason97
20175Jason55
20176Jason57
20177Jason72
20178Jason53
20179Jason72
201710Jason87
201711Jason50
201712Jason72
20182Jason70
20183Jason68
20184Jason84
20185Jason62
20186Jason53
20187Jason91
20188Jason79
20189Jason94

 

 

ex.jpg

Hi @cosminc 

I replied your lastest post.

https://community.powerbi.com/t5/Desktop/index-dax/m-p/631023#M301675

Does my solution solve that case?

 

If my solution help, to get this visual to show only top5 salesman, just add "rankx" meausre in the "Visual level filter" and select "less than 6".

 

For this case, i have something unclear.

If you still have problem, could you kindly make me clear?

16.png

From you screenshot, i don't know which you select from the slicer, year=2019, month=2 ???

If you select (year=2019,month=2), then the visual should show

(year=2019,month=1year=2019,month=2year=2018,month=2), right???

 

Best Regards

Maggie

 

hi

i want to make a fixed graph not to select manually with the slicer

so when i'll have also data for march i want to see on the graph 2019 - 3 (march), 2019 - 2 (feb) and 2018 - 3 (march previous year)

think at it like a presentation without slicers on it, which will be updated automatically

thanks,

Cosmin

Hi @cosminc 

It seems possible.

This workaround is based on the following assumption.

assume today=2019/2/27, then you have data until 2019/2

if today is 2019/3/2, then you have data until 2019/3

screenshot1->when today=2018/2/27

screentshot2->when today=2019/3/2 (from screenshot1 to2, just refresh the data when coming to a new month).

3.png

4.png

then i work as below

create a calculated column

year-month = [Year]&"-"&[MonthNo]

create measures

flag1 =
IF (
    (
        YEAR ( TODAY () ) = MAX ( Sheet7[Year] )
            && (
                MONTH ( TODAY () ) = MAX ( Sheet7[MonthNo] )
                    || MONTH ( TODAY () ) - 1
                        = MAX ( Sheet7[MonthNo] )
            )
    )
        || (
            YEAR ( TODAY () ) - 1
                = MAX ( Sheet7[Year] )
                && MONTH ( TODAY () ) = MAX ( Sheet7[MonthNo] )
        ),
    1,
    0
)
flag2 = IF(YEAR(TODAY())=MAX(Sheet7[Year])&&MONTH(TODAY())=MAX(Sheet7[MonthNo]),1,0)
sales_this month = CALCULATE(SUM(Sheet7[Sales]),FILTER(ALLEXCEPT(Sheet7,Sheet7[Salesman]),[flag2]=1))

sales new = CALCULATE(SUM(Sheet7[Sales]),FILTER(ALLEXCEPT(Sheet7,Sheet7[Salesman],Sheet7[year-month]),[flag1]=1))

new ranks = RANKX(FILTER(ALL(Sheet7),[flag1]=1),[sales_this month],,DESC,Dense)

See my pbix for more details.

 

Best Regards

Maggie

 

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

Hi

Thanks a lot

the idea is that i update the base monthly with previous month (on 4 march i updated with feb 2019) and the calendar is up to 31 dec 2019

the data base is on monthly level (i made an improvisation to have a day column with first day of each month and this way to put in relationship with the calendar) and slicers are on year and month level; i have in mind that column year - month would be useful on this case - base on it a measure with filter max year-month number, -1 and -12

i will analize your solution and maybe i can adapt it to the situation

thanks

Cosmin

Hi,

 

Perhaps someone else will help you.  I do not understand the meaning of "Top 5 salesman after sales of last month"?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi,

imagine that you make a top (ranked) with salesmen after their sum of sales

but after their last sales - from feb 2019 in this case 

thanks!

 

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.