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
casperholtfarve
Helper III
Helper III

Compare number with previous periods from earlier years WITHOUT an actual date field

Hi everyone,

 

I am not sure whether or how this is possible, but I hope someone can clarify.

 

I have a data model containing some numbers (lets call the sales).

And then a table containing the following: Year, Quarter number, Month number and year_month number (fx. 202001).

I do NOT have a specific date available.

 

I can show the "sales" like this:

casperholtfarve_0-1659334493793.png

And it continues to 202207. 

 

What I would like to accomplish is the following:

 

I would like to sum up all the "sales" for the current year:

casperholtfarve_1-1659334574473.png

So in this example it is 67.477.

 

Then i would like to showcase the "sales" for the same months for the previous years (2018, 2019, 2020 and 2021). This means the sum of 201801 - 201807, 201901 - 201907, etc.

 

I know it should probably be easy with bultin functionality in Power BI if I have registered dates. But since I do not, is there another way to accomplish this?

 

Also I would like it to be dynamic. Meaning, that once we have passed august (month 😎 - hence 1. of september, I would like it to show 202201 - 202208, and the corresponding values for previous years as well.

 

Hope it makes sense and that somebody got a fix 🙂

 

Thanks in advance.

/Casper.  

1 ACCEPTED SOLUTION
casperholtfarve
Helper III
Helper III

I think I found the solution after a little trial and error:

Measure =
VAR lastMonth =
MONTH(
TODAY()
) -1

RETURN
SUMX(
FILTER(
ALL('Date table');
'Date table'[month_number] <= lastMonth &&
'Date table'[year] = MAX('Date table'[year])
);
[Sales]
)

[Sales] was an existing standard measure summing the sales.

View solution in original post

7 REPLIES 7
casperholtfarve
Helper III
Helper III

casperholtfarve_0-1660025476644.png

Comparing the full sales of the year to the sales for the first 7 months each year 🙂
And I have verified it as well with the rows for each month.

Thanks for the assist @v-jianboli-msft 

 

casperholtfarve
Helper III
Helper III

I think I found the solution after a little trial and error:

Measure =
VAR lastMonth =
MONTH(
TODAY()
) -1

RETURN
SUMX(
FILTER(
ALL('Date table');
'Date table'[month_number] <= lastMonth &&
'Date table'[year] = MAX('Date table'[year])
);
[Sales]
)

[Sales] was an existing standard measure summing the sales.
v-jianboli-msft
Community Support
Community Support

Hi @casperholtfarve ,

 

Please try:

Measure 2 = 
var _a = CALCULATE(MAX('Table'[Year_Month]),ALL('Table'))
var _b = VALUE( MAX('Table'[Year])&RIGHT(_a,2))
return SUMX(FILTER(ALL('Table'),[Year_Month]<=_b&&[Year]=MAX('Table'[Year])),[Sales])

Output:

vjianbolimsft_0-1659605488813.png

Best Regards,

Jianbo Li

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

Okay the 2 tables are not an issue.

But another issue has occured.

 

It seems like, that the table with the year_month, actually contains all the year_month even though we have not reached the point yet.

 

Meaning for 2022 the table contains all the month:

202201
202202

202203

202204

202205

202206

202207

202208

202209

202210

202211

202212

 

This messes up the measure above as the previous years then gets ALL the data from all the years.
Is it possible somehow NOT to use the MAX function but instead a function that looks at todays month number -1? Then we will always only look at all the previous months of the year from whatever month you ar ecurrently in?

Thanks a lot.
It looks very promissing. But what if sales and years_month (and years) values are stored in to seperate tables?

Is it still possible? The two tables are obviously connected. And I guess this should modify the SUMX() if the measure?

Thanks in advance.

lukiz84
Memorable Member
Memorable Member

Can you show the source table? Just some dummy rows?

Hi lukiz84,

 

These are the 2 tables:

 

"Date"-table (without acutal dates):

casperholtfarve_0-1659350647939.png

It is developed in a Cube at my work with many more tables. 

 

The "Sales" numbers are a measure that sums up the numbers.

Put together it gives this (like I also snapped in the initial post):

casperholtfarve_1-1659350906983.png

 


 

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.