Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
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
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. 😊
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
| User | Count |
|---|---|
| 12 | |
| 9 | |
| 8 | |
| 5 | |
| 3 |
| User | Count |
|---|---|
| 28 | |
| 22 | |
| 20 | |
| 18 | |
| 12 |