简体   繁体   English

如何将当月第一天的总销售额计算为power BI中的上个月销售额

[英]How to calculate total sales as of first day of the current month as Previous month sales in power BI

I have salesamount column and the saledate column in my table.我的表中有 salesamount 列和 saledate 列。 so I need to calculate total sales for each month based on below calculation.所以我需要根据以下计算计算每个月的总销售额。

total sales for current month=sum(salesamount) as of 1st day of the next month本月总销售额=sum(salesamount) 截至下月1日

for example sales of December-2021 should be calculated based on the total sales as on Jan-1-2022.例如,2021 年 12 月的销售额应根据 2022 年 1 月 1 日的总销售额计算。 total sales for January should be blank until Feb-1-2022 as it should be the total sales as on feb-1-2022.一月份的总销售额在 2022 年 2 月 1 日之前应该是空白的,因为它应该是 2022 年 2 月 1 日的总销售额。 I am very much confused how we can achieve this in Dax.我很困惑我们如何在 Dax 中实现这一点。 Really appreciate your help.非常感谢您的帮助。

If I understand your question correctly, you can use the following DAX measure:如果我正确理解您的问题,您可以使用以下 DAX 度量:

Total Sales = 
var currentDate = MAX(myTable[saleDate])
var firstOfMonth = DATE(YEAR(CALCULATE(MAX(myTable[saledate]), ALL(myTable))),
    MONTH(CALCULATE(MAX(myTable[saledate]), ALL(myTable))), 1)
var result = SUM(myTable[salesamount])

Return IF(currentDate < firstOfMonth, result)

This will take the current date of the report context and compare it to the 1st of the current month.这将获取报告上下文的当前日期并将其与当前月份的 1 日进行比较。 If the currentDate is less than the 1st of the current month, the result will be calculated.如果 currentDate 小于当月 1 日,则计算结果。 If your dataset has a Date table, you can replace the 'myTable[saledate]' references with a reference to the Date column in your date table.如果您的数据集有一个日期表,您可以将“myTable[saledate]”引用替换为对日期表中日期列的引用。

With some sample data, here are the results:使用一些示例数据,结果如下:

桌子

(I added the firstOfMonth column for demonstration purposes) (出于演示目的,我添加了 firstOfMonth 列)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获取当前周和月的第一天? - How to get the first day of the current week and month? 如何获取当月,第一天,零小时的时间戳 - How to get timestamp of current month, first day of month, zero hour 需要在Power BI中设置上个月底 - Need to set the end of previous month in Power BI 在 PySpark 中用零填充缺失的销售值并计算 3 个月的平均值 - Filling Missing sales value with zero and calculate 3 month average in PySpark Power BI 中客户级别的当前月/年差异 - Difference current month / month a year back on customer level in Power BI 将本月的日期与上个月的同一天进行比较 PostgreSQL - Compare day in current month to same day previous month PostgreSQL 将日设置为“月的第一天”,如果已设置,则设置为上个月 - Set day to “first day of month”, if it's set, set to previous month 如何使用 Carbon 获取上个月的第一天和最后一天 - Laravel - How to get First and Last Day of Previous Month with Carbon - Laravel 如何在 Google BigQuery 中检索上个月的第一天和最后一天? - How to retrieve first and last day of the previous month in Google BigQuery? MySQL:选择上个月的第一天和最后一天 - MySQL: Select with first and last day of previous month
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM