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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Gaga_Jin
Frequent Visitor

Dax Formula

hi, there. 

This is a code that calculates a player's bonuses based on their performance. if a player is entitled to a bonus or not, is determined by "Eligible" Measure. it shows 1 or 0. if 1, then bonus should be awarded . The mechanism of operation is as follows. If a player has Eligible = 1 on the first day, then he received a certain amount (for example: 500,000), if on the second day, then he received 1,000,000, if on the third, then 1,500,000. If he messed up this sequence, he will not receive anything. However, from the next day he can continue this progress. My code cannot look at the previous day, and every day if the player's Eligible = 1 - it writes only 500,000 and does not look at the previous day's activity.


guy's you can offer our versions. will be glad. 

The problem is shown on a screen.

Gaga_Jin_0-1734007087987.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Gaga_Jin ,

 

You can try this method and it worked in my test.

1. Calculates the date on which the last Eligible was 0 based on the current date.

2. Calculate the date difference and multiply by 5,000,000 to get the cumulative reward.

 

Situations to consider are:

1. Whether the current date is the minimum date

2. There are no rows with an Eligible of 0.

 

Here are my test data.

vmengmlimsft_0-1734078002344.png

Expected output:

vmengmlimsft_1-1734078045044.png

The DAX.

Bonus = VAR current_date = MAX('Table'[Date])
VAR MinDate = MINX(ALL('Table'),'Table'[Date])
VAR Date_Table = FILTER(ALL('Table'),'Table'[Eligible]=0&&'Table'[Date]<=current_date&&'Table'[ID]=MAX('Table'[ID]))
VAR last_date = IF(ISEMPTY(Date_Table),MinDate-1,CALCULATE(MAX('Table'[Date]),ALL('Table'),'Table'[Eligible]=0&&'Table'[Date]<=current_date&&'Table'[ID]=MAX('Table'[ID])))
RETURN  DATEDIFF(last_date,current_date,DAY)*5000000

vmengmlimsft_2-1734078111878.png

 

 

 

Best regards,

Mengmeng Li

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Gaga_Jin ,

 

You can try this method and it worked in my test.

1. Calculates the date on which the last Eligible was 0 based on the current date.

2. Calculate the date difference and multiply by 5,000,000 to get the cumulative reward.

 

Situations to consider are:

1. Whether the current date is the minimum date

2. There are no rows with an Eligible of 0.

 

Here are my test data.

vmengmlimsft_0-1734078002344.png

Expected output:

vmengmlimsft_1-1734078045044.png

The DAX.

Bonus = VAR current_date = MAX('Table'[Date])
VAR MinDate = MINX(ALL('Table'),'Table'[Date])
VAR Date_Table = FILTER(ALL('Table'),'Table'[Eligible]=0&&'Table'[Date]<=current_date&&'Table'[ID]=MAX('Table'[ID]))
VAR last_date = IF(ISEMPTY(Date_Table),MinDate-1,CALCULATE(MAX('Table'[Date]),ALL('Table'),'Table'[Eligible]=0&&'Table'[Date]<=current_date&&'Table'[ID]=MAX('Table'[ID])))
RETURN  DATEDIFF(last_date,current_date,DAY)*5000000

vmengmlimsft_2-1734078111878.png

 

 

 

Best regards,

Mengmeng Li

mark_endicott
Super User
Super User

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.