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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.