How to calculate sum of amount for current month including the amount of previous months in Power Bi? - sum

I would like to create DAX expression. This is the condition and I have my month and year table in separate column.
If we choose Month as a March then it should show the sum of amount of Jan, Feb and as well as March. Similarly, If we choose Month as Dec then it should have the sum from Jan to Dec.
How can we write DAX expression for this condition in Power Bi?

You probably need a measure as below. You need to have a separate Date/Calendar table for that which is connected to your Data table using Date column.
total_amount_ytd =
CALCULATE(
SUM(your_table_name[your_amount_column_name]),
DATESYTD(your_date_table_name[your_date_column_name])
)
With this above Measure, if you add Year/Month in a table with the new Measure, you will find the value per year will increase from January to December for a single year and starts re calculating from January again in the next year.

Related

I am trying to get a month and year to date column in SQL

I am trying to create a month and year to date column but the FY starts from October and I need it to roll into the next year so this can automatically update in Power Bi I have the Date ID for our year now maybe need flags to show the current month and current year then I can create a measure in Power Bi, also need it to sum up the months for year to date etc if I click january it shows me sales from October to January.

MDX Calculated Measure Year to Date

I have an OLAP multi dimensional cube, which in its simplest form contains:
A fact table with a NetAmount measure
A Time dimension, with fields for Year, Month, Day, Day of Month, Day of Year, etc
The requirement is that the user wants to be able to compare the total NetAmount from the beginning of each year up to a specific date. The date can be chosen by setting filters on the Day and Month fields. For example, the user wants to see total value for:
01 Jan 2019 to 20 Jan 2019
01 Jan 2018 to 20 Jan 2018
01 Jan 2017 to 20 Jan 2017
etc
What would be the best way to tackle this requirement?
You can create calculated member with YTD function like this:
CREATE MEMBER CURRENTCUBE.[Measures].[NetAmountYTD]
as
Aggregate(YTD ([Time].[Time].CurrentMember), [Measures].[NetAmount])
You could also create Utility dimension for example TimeUtility, and add YTD member, and define it like this:
Scope([TimeUtility].[YTD]);
this = Aggregate(YTD ([Time].[Time].CurrentMember), [TimeUtility].[DefaultMember]);
End Scope;
This way whatever measure you look against [TimeUtility].[YTD] it will give you Year to Date for that measure, not just NetAmount, so it will be general solution.

Power BI - Difference between amount per day and total in a table

I have a table with the sales from last 2 years, and I want to compare the sales from this year with the same natural day last year. For example, Sunday 1st of April 2018 will be compared with Sunday 2nd April 2017.
In order to do that I have created the measure
sales_last_year = CALCULATE(Sales[Revenue]); SAMEPERIODLASTYEAR(DATEADD('Calendar'[Date];+1;DAY)))
And I have created another measure where I have the value from the same day last year:
Prueba_sales_last_year = CALCULATE(Sales[Revenue]); SAMEPERIODLASTYEAR('Calendar'[Date]))
The result is the following:
Sales last year
As you can see the sales per day shows 5.316€ and 3.546€, which is correct, but the total is 111.796 €, which is not correct. However, the measure with the formula without the natural day the sum of the two rows is correct. How could I solve this?
Thank you very much in advance
I just changed the order to calculate the date and it was solved.
sales_last_year = CALCULATE(Sales[Revenue]);DATEADD( SAMEPERIODLASTYEAR('Calendar'[Date]);+1;DAY))

Missing a grand total for my month over month measure

I have a measure that gives me the month over month change in budget. The measure is defined as:
Bugdet Month over Month:=if(and(sum(budget[Value])<>0;[Budget, Previous Month]<>0);sum(budget[Value])-[Budget, Previous Month];0)
Budget, Previous Month:=CALCULATE(sum(budget[Value]);PREVIOUSMONTH(tDate[Date]))
When I show Bugdet Month over Month in a pivot table, it shows the correct numbers, but it shows 0 in the grand total. Is it possible to make some change somewhere to make it show the sum of all changes in the grand total?
Rough take is create a third measure:
Budget Month over Month Final:=SUMX ( VALUES(tdate[Date]), [Budget Month over Month])
This will independently iterate over every month in the given cell and calculated Budget Month over Month and then SUM them together. So for the month row values in your pivot table, this will be the equivalent of the current Budget Month over Month measure.
And for the Grand Total it will then show the sum of each individual month in the pivot.

how to summarize sql result, week and month wise in single query

I want to summarize sql query result week wise and month wise at the same time in a grid view. Is this even possible or I am just dreaming?
Requirement:
Show last one month data and next two month's data week wise in the grid.
Example-
If the current month is September then I want to show data from 1st August to 31st October categorized in weeks.
Show the data after the next month of current month in month wise view in the same grid.
Example-
data for month November and December will be shown categorized in month not in weeks.
grid or result should look something like below -
Please suggest something to achieve this
If you want a maintainable solution, use two independent queries, one for weekly aggregation other for monthly. Depending on the input run corresponding query.
I think you must work with group by or group by ... cube
SELECT x , y from <tabel> GROUP BY date_feld( to_char( 'MM' ))
but i don't now your DBMS so i can't give you a exact example for the date handling.