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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
dgn8890
New Member

Total sales of Current month, if current month is zero results it should return previous month sales

How to calculate total current month sales if there is no sales in current month  it should return previous month sales .

example

month: Jan Feb mar Apr May aug

Sales : 10,21,no results,no results,no results

 

1 REPLY 1
Alef_Ricardo_
Resolver II
Resolver II

To calculate the total sales of the current month, you can use a conditional statement to check if the sales for the current month are zero or not. If the sales for the current month are zero, then you can return the sales for the previous month. Here is an example code in Python that demonstrates this:

 

def get_sales(sales: list, current_month: int) -> int:
if sales[current_month] == 0:
return sales[current_month - 1]
else:
return sales[current_month]

# Example
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Aug']
sales = [10, 21, 0, 0, 0]
current_month = 4 # May

print(f"Total sales for {months[current_month]}: {get_sales(sales, current_month)}")

 

This code defines a function get_sales that takes in a list of sales and an integer representing the current month. The function checks if the sales for the current month are zero, and if they are, it returns the sales for the previous month. Otherwise, it returns the sales for the current month.

 

In the example, we have a list of months and a list of sales. We set the current month to be May (represented by the index 4 in the months list). When we call the get_sales function with these inputs, it returns 21, which is the sales for the previous month (April).

 

I hope this helps! Let me know if you have any questions or need further clarification. 😊

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.