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
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

@ 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...

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

@ 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_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?


@ 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...

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

@BJankic Yes please!


@ 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...

@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
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.