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
mdaamirkhan
Post Prodigy
Post Prodigy

How to calculate sales from specify year

Hi All,

 

I need help on dax How to calculate sales from specify year  as I have multiple year. I want to  calculate sales from 2021 1st Jan till 2025 or so on

Capture.JPG

4 ACCEPTED SOLUTIONS
PhilipTreacy
Super User
Super User

Hi @mdaamirkhan 

 

Download sample PBIX file

 

Your question isn't very clear and you have only provided a column of dates, no other data.

Are you trying to calculate sales for a selected year e.g. Sales for 2019, Sales for 2020 etc?

If so, and if you have data like this,

sal1.png

then you just need a slicer showing the years in your dates and this measure

Sales for Year = IF(ISFILTERED('Table'[Date].[Year]),CALCULATE(SUM('Table'[Sales]), FILTER(ALL('Table'), YEAR('Table'[Date]) = YEAR(MAX('Table'[Date])))),"")

sal2.png

This isn't using a DateTable.  If you have a dateTable the measure will be different.  Please provide more information and an exampleof your desired result.

regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

Jihwan_Kim
Super User
Super User

Hi,

I am not sure if you need to figure it out like below, but please correct me if I were wrong.
Please check the below DAX measure, picture, and link.

 

Picture1.png

 

Value total from year2021 =
VAR fromwhatyear = 2021
VAR newtable =
CALCULATETABLE (
SUMMARIZE (
ALLSELECTED ( Data ),
Data[date],
"@valuetotal", [Value total]
),
Dates[Year] >= fromwhatyear
)
RETURN
IF (
HASONEVALUE ( Dates[date] ),
IF (
SELECTEDVALUE ( Dates[Year] ) >= fromwhatyear,
CALCULATE (
[Value total],
Dates[Year] >= fromwhatyear
),
IF (
SELECTEDVALUE ( Dates[Year] ) < fromwhatyear,
BLANK ()
)
),
SUMX (
newtable,
[@valuetotal]
)
)
 
Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.
 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

I appiled your dax but it shwoing same value duplicate 

Total past revenue_2018 =

VAR fromwhatyear = 2018
VAR newtable =
CALCULATETABLE (
SUMMARIZE (
ALLSELECTED ( Invoice_Report ),
Invoice_Report[Invoice date],
"@valuetotal", [Total past revenue]
),
Invoice_Report[Year] >= fromwhatyear, ALLEXCEPT(Invoice_Report,Invoice_Report[Contract Code])
)
RETURN
IF (
HASONEVALUE ( Invoice_Report[Invoice date] ),
IF (
SELECTEDVALUE ( Invoice_Report[Year] ) >= fromwhatyear,
CALCULATE (
[Total past revenue],
Invoice_Report[Year] >= fromwhatyear
),
IF (
SELECTEDVALUE ( Invoice_Report[Year] ) < fromwhatyear,
BLANK ()
)
),
SUMX (
newtable,
[@valuetotal]
)
)


Capture.JPG

View solution in original post

PhilipTreacy
Super User
Super User

Hi @mdaamirkhan 

I don't see anywhere that you have provided sample data in an Excel or PBIX file. Please re-post the link.

What you want still remains a little unclear.

Do you want (for example) cards that show the sales for each year?  The meaning of the red lines in your images isn't clear.  I don't know what they are meant to indicate.

regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

10 REPLIES 10
PhilipTreacy
Super User
Super User

Hi @mdaamirkhan 

I don't see anywhere that you have provided sample data in an Excel or PBIX file. Please re-post the link.

What you want still remains a little unclear.

Do you want (for example) cards that show the sales for each year?  The meaning of the red lines in your images isn't clear.  I don't know what they are meant to indicate.

regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Jihwan_Kim
Super User
Super User

Hi,

I am not sure if you need to figure it out like below, but please correct me if I were wrong.
Please check the below DAX measure, picture, and link.

 

Picture1.png

 

Value total from year2021 =
VAR fromwhatyear = 2021
VAR newtable =
CALCULATETABLE (
SUMMARIZE (
ALLSELECTED ( Data ),
Data[date],
"@valuetotal", [Value total]
),
Dates[Year] >= fromwhatyear
)
RETURN
IF (
HASONEVALUE ( Dates[date] ),
IF (
SELECTEDVALUE ( Dates[Year] ) >= fromwhatyear,
CALCULATE (
[Value total],
Dates[Year] >= fromwhatyear
),
IF (
SELECTEDVALUE ( Dates[Year] ) < fromwhatyear,
BLANK ()
)
),
SUMX (
newtable,
[@valuetotal]
)
)
 
Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.
 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


I appiled your dax but it shwoing same value duplicate 

Total past revenue_2018 =

VAR fromwhatyear = 2018
VAR newtable =
CALCULATETABLE (
SUMMARIZE (
ALLSELECTED ( Invoice_Report ),
Invoice_Report[Invoice date],
"@valuetotal", [Total past revenue]
),
Invoice_Report[Year] >= fromwhatyear, ALLEXCEPT(Invoice_Report,Invoice_Report[Contract Code])
)
RETURN
IF (
HASONEVALUE ( Invoice_Report[Invoice date] ),
IF (
SELECTEDVALUE ( Invoice_Report[Year] ) >= fromwhatyear,
CALCULATE (
[Total past revenue],
Invoice_Report[Year] >= fromwhatyear
),
IF (
SELECTEDVALUE ( Invoice_Report[Year] ) < fromwhatyear,
BLANK ()
)
),
SUMX (
newtable,
[@valuetotal]
)
)


Capture.JPG

Hi, @mdaamirkhan 

Thank you for your feedback.

I think, if the model is different, sometimes it creates an unexpected result.

Did you see my sample PBIX file?

I think, at least it works in my sample PBIX file.

If you can share your sample pbix file, please share it. 

If it is possible, I can try to create another measure based on your model.

Thank you very much.

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


PhilipTreacy
Super User
Super User

Hi @mdaamirkhan 

 

Download sample PBIX file

 

Your question isn't very clear and you have only provided a column of dates, no other data.

Are you trying to calculate sales for a selected year e.g. Sales for 2019, Sales for 2020 etc?

If so, and if you have data like this,

sal1.png

then you just need a slicer showing the years in your dates and this measure

Sales for Year = IF(ISFILTERED('Table'[Date].[Year]),CALCULATE(SUM('Table'[Sales]), FILTER(ALL('Table'), YEAR('Table'[Date]) = YEAR(MAX('Table'[Date])))),"")

sal2.png

This isn't using a DateTable.  If you have a dateTable the measure will be different.  Please provide more information and an exampleof your desired result.

regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


without any yrar slicer I want to calculate sales amount starting from 2021 til so on.

As I have few years like 2019 , 2020 , 2021 , 2022 , 2023, 204

Jihwan_Kim
Super User
Super User

Hi,

I was reading your question, but sorry to say that your attached picture made me a little bit confused.

May I ask what is the meaning of the red-color marks?

If it is OK with you, please share the sample data, then I can try to create a DAX, if possible.

Thank you very much.

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


I already share the data in the excel file also share the link to download. red color line mean I am referring that date is like that. 

still I didn't get any update 

Will I get any solution from the group

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.