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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Franco
Frequent Visitor

Dax LikeForLike previous year

Hi all,

we are facing the following issue:

We have to calculate the total amount of transactions table (month per month) of the previous year only for POS that in the current/selected year have LikeForLike column = TRUE.

 

The measure TotalTransaction is CALCULATE(SUM(Transactions[Transactions]),Transactions[LikeForLike] = TRUE())

But the TotalTransaction for previous year cannot be calculate simply using CALCULATE(SUM(Transactions[Transactions]),Transactions[LikeForLike] = TRUE(), SAMEPERIODLASTYEAR(Date)) because it would calculate the amount of the last year but for POS that have LikeForLike = TRUE in the previus year.

If i should write it in SQL i would do like the following script:

Select sum(transactions) from transactions 
where year(date) = 2019 and
pos in (
Select distinct pos where year(date) = 2020 and lfl = true
)


 thanks in advance for your reply

Franco

2 REPLIES 2
amitchandak
Super User
Super User

@Franco , Not very clear.

Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

 

you should use date table

CALCULATE(SUM(Transactions[Transactions]),Filter(Transactions,Transactions[LikeForLike] = TRUE()))

 

last year measure

= CALCULATE(SUM(Transactions[Transactions]),Filter(Transactions,Transactions[LikeForLike] = TRUE()),SAMEPERIODLASTYEAR(Date[Date]))

 

 

= CALCULATE(SUM(Transactions[Transactions]),Filter(Transactions,Transactions[LikeForLike] = TRUE()),dateadd(Date[Date],-1,year))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

@amitchandak many thanks for the answer.

 

Below the link to a Pibx with example.

https://www.dropbox.com/s/eixqy5saw5k8k2a/Demo_LikeForLike.pbix?dl=0

 

Thanks in advance,

Franco

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.