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
BJankic
Frequent Visitor

Calculate Contract Renewed Amount in Second Column

Hi,

 

I'm trying to calculate renewed amount in second column (renewed value). This is original data information

 

account_idaccount_nameservice_contract namecontract_stageservice_contract_valuerenewed valueservice_contract_start_dateservice_contract_end_date
1account_name_1service_contract name_1closed_won$2,000.00 1/1/20221/1/2023
1account_name_1service_contract name_2closed_won$3,000.00 1/1/20231/1/2024
2account_name_2service_contract name_3closed_won$4,000.00 1/1/20221/1/2023
2account_name_2service_contract name_4closed_won$5,000.00 1/1/20231/1/2024
3account_name_3service_contract name_5closed_won$6,000.00 1/1/20221/1/2023
3account_name_3service_contract name_6closed_won$7,000.00 1/1/20231/1/2024
4account_name_4service_contract name_7closed_won$8,000.00 1/1/20221/1/2023
4account_name_4service_contract name_8closed_won$9,000.00 1/1/20231/1/2024

 

This is the desired outcome : 

 

account_idaccount_nameservice_contract namecontract_stageservice_contract_valuerenewed valueservice_contract_start_dateservice_contract_end_date
1account_name_1service_contract name_1closed_won $                           2,000.00 $           3,000.001/1/20221/1/2023
1account_name_1service_contract name_2closed_won $                           3,000.00 1/1/20231/1/2024
2account_name_2service_contract name_3closed_won $                           4,000.00 $           5,000.001/1/20221/1/2023
2account_name_2service_contract name_4closed_won $                           5,000.00 1/1/20231/1/2024
3account_name_3service_contract name_5closed_won $                           6,000.00 $           7,000.001/1/20221/1/2023
3account_name_3service_contract name_6closed_won $                           7,000.00 1/1/20231/1/2024
4account_name_4service_contract name_7closed_won $                           8,000.00 $           9,000.001/1/20221/1/2023
4account_name_4service_contract name_8closed_won $                           9,000.00 1/1/20231/1/2024

 

Your help is much appreciated,

 

Thank you,

 

Bojan

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@BJankic Try something like:

Column = 
  VAR __AccountID = [account_id]
  VAR __Start = [service_contract_start]
  VAR __Next = MINX(FILTER(ALL('Table'),[account_id] = __AccountID && [service_contract_start] > __Start),[service_contract_start])
  VAR __Value = MINX(FILTER(ALL('Table'), [account_id] = __AccountID && [service_contract_start] = __Next), [service_contract_value]
RETURN
  __Value


Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

8 REPLIES 8
BJankic
Frequent Visitor

Thank you, @Greg_Deckler !

Greg_Deckler
Super User
Super User

@BJankic Try something like:

Column = 
  VAR __AccountID = [account_id]
  VAR __Start = [service_contract_start]
  VAR __Next = MINX(FILTER(ALL('Table'),[account_id] = __AccountID && [service_contract_start] > __Start),[service_contract_start])
  VAR __Value = MINX(FILTER(ALL('Table'), [account_id] = __AccountID && [service_contract_start] = __Next), [service_contract_value]
RETURN
  __Value


Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler ,

 

I have a situation for this calculation that is not cathing the renewal value.

 

This one is okay :

 

Screenshot_1.jpg

 

These are not, probably because of the start date : 

Screenshot_2.jpg

Screenshot_3.jpg

 

Any chance you can update the formula?

 

Thank you.

 

Bojan

@BJankic Is that scenario in the sample data?



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler It is not. Do you want me to send you new sample?

@BJankic Yes please!



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler here it is sir.

 

Original : 

 

account_idaccount_nameservice_contract namecontract_stageservice_contract_valuerenewed valueservice_contract_start_dateservice_contract_end_date
1account_name_1service_contract name_1closed_won$2,000.00 1/1/20221/1/2023
1account_name_1service_contract name_2closed_won$3,000.00 1/1/20231/1/2024
2account_name_2service_contract name_3closed_won$4,000.00 1/1/20221/1/2023
2account_name_2service_contract name_4closed_won$5,000.00 1/1/20231/1/2024
3account_name_3service_contract name_5closed_won$6,000.00 1/1/20221/1/2023
3account_name_3service_contract name_6closed_won$7,000.00 1/1/20231/1/2024
4account_name_4service_contract name_7closed_won$8,000.00 1/1/20221/1/2023
4account_name_4service_contract name_8closed_won$9,000.00 1/1/20231/1/2024
5account_name_5service_contract name_9closed_won$560,150.00 1/2/20221/1/2023
5account_name_5service_contract name_10closed_won$582,120.00 1/20/20231/19/2024
6account_name_6service_contract name_11closed_won$140,000.00 1/2/20221/1/2023
6account_name_6service_contract name_12closed_won$145,530.00 1/20/20231/19/2024

 

Desired outcome : 

account_idaccount_nameservice_contract namecontract_stage service_contract_value  renewed value service_contract_start_dateservice_contract_end_date
1account_name_1service_contract name_1closed_won  $                           2,000.00   $           3,000.00 1/1/20221/1/2023
1account_name_1service_contract name_2closed_won  $                           3,000.00  1/1/20231/1/2024
2account_name_2service_contract name_3closed_won  $                           4,000.00   $           5,000.00 1/1/20221/1/2023
2account_name_2service_contract name_4closed_won  $                           5,000.00  1/1/20231/1/2024
3account_name_3service_contract name_5closed_won  $                           6,000.00   $           7,000.00 1/1/20221/1/2023
3account_name_3service_contract name_6closed_won  $                           7,000.00  1/1/20231/1/2024
4account_name_4service_contract name_7closed_won  $                           8,000.00   $           9,000.00 1/1/20221/1/2023
4account_name_4service_contract name_8closed_won  $                           9,000.00  1/1/20231/1/2024
5account_name_5service_contract name_9closed_won $                       560,150.00 $      582,120.001/2/20221/1/2023
5account_name_5service_contract name_10closed_won $                       582,120.00 1/20/20231/19/2024
6account_name_6service_contract name_11closed_won $                       140,000.00 $      145,530.001/2/20221/1/2023
6account_name_6service_contract name_12closed_won $                       145,530.00 1/20/20231/19/2024

@Greg_Deckler Did you manage to solve it, is there an issue with the dataset?

 

Thank you.

 

Bojan

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!

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.