How to consolidate the sales data using DAX - powerbi

Hi everyone,
I have a data table named as sales in PBI as shown in the screenshot above. I want to create a matrix visualizer to consolidate all the sales by month. The expected output for the matrix will be something like this:
I'm having challenge to use DAX formula to consolidate the sales. Right now, I'm using SUM(sales[Sales]) to calculate, but what I got in the matrix for each rows is the total sales. I tried to used SUMX as well but it doesn't work either. Any help or advise will be greatly appreciated!

If you have it stored as a string SUM functions won't work - which is the only error I can think of with data as simple as that.
You also don't need to make a function for something like this. Just make a new table with "Month & Year" and "Sales" it'll default to using SUM of sales if it's stored as a number or integer.

Related

How do I create measures that are not aggregated data?

I have a simple table which has a number(say sales) as one column which describes the sales done for a product. I also have ~25 products.
Now, I want to import this sales as a measure into cube. However, i am not sure what it's type and sql parameters should be. Setting the type to 'number' and sql to 'sales' gives error such as column "plan.sales" must appear in the GROUP BY clause or be used in an aggregate function.
What am I doing wrong?
Сould you please share the env vars, the cube.js file, and the data schema?
I also recommend you follow up through this guide. I think it might help.
I think you should add the sales column as a dimension, then you can define the aggregated measures like average sales or total of sales using the number of sales dimension.

Is DAX from Power BI same as LOD in Tableau

I'm new to tableau. my question is, is DAX from Power BI same as LOD in Tableau?
It'd be great if someone could help me with an explanation for this.
thanks in advance!
There are similarities for sure. In Excel it can be a way to display a value that is unaffected by filtering.
LODs are similar in that you can fix your value.
For example, if I want to know the total sales in a workbook regardless of what row/column the value is on, I could use a FIXED LOD expression:
{FIXED : SUM([Sales]}
If you put the above on Label and a Month dimension on rows, it will ignore the segmentation of months and display the total sum of sales for the entire workbook.
You can choose to fix on a different level of detail to achieve a different result:
{FIXED [Month] : SUM([Sales]}
If you put the above on Label and a month and date dimension on rows it will display the total sum of sales for each month, and ignore the date. And so on...
They're somewhat tricky to get used to, but they come up a lot in more complex workbooks.
I would put it this way, the DAX language is at least as powerful as Tableau expressions (involving LOD or otherwise). That is, if you can do it with Tableau LOD, then there's also a way to write something equivalent with DAX.

Calculate % of two columns Power BI

I want to calculate % of two columns which are already in %.
I want to calculate formula like
Target achieved= ACTUAL/TARGET
But here is ACTUAL is already a measure/calculated metrics so I'm not able to divide these two columns.
Any help would be appreciated..
Make sure both target and actual are actually numbers and not strings. You can do it in transform data (aka Power Query) part, before data is loaded into the report.
After that you should be able to create the measure you want, e.g. something like that:
UPDATE : What happens if Actual is not a column, but a measure?
If Actual measure is based on the columns in the same table as target you shouldn't have a problem. You cannot combine measure and column in the same formula. Measure is an aggregated field and needs to be grouped by another field (if you are familiar with SQL,think of SUM and GROUP BY). Coming back to your problem, you need to create measure out of "Target" column as well (notice I have in the formula SUM('Table'[Plan]) which makes it a measure). Than you can use both of them in the formula, but of course you need to "group" them by something(e.g. date) otherwise it will just show you a total.

Power BI YTD Calculations

I am trying to do some time based calculations on my budgeting data but struggling to understand where I'm going wrong or if my data structure would even support what I'm trying to do.
As per the image above, this is my raw data. ie. A monthly budgeted and actual total for each cost centre that is being imported from an excel spreadsheet.
I am trying to calculate a YTD budget and YTD Actual figure per cost centre based on the monthly totals. Ideally I would like all of this data displayed in a table that I can then use slicers to segment/pivot.
When using the CALCULATE() function in a measure, I am unable to select my cell value for each date and cost centre.
eg.
YTD Actual = CALCULATE( [Actual MTH] , DATESYTD('Dates'[Date], "30/6"))
returns the error
The value for 'Actual MTH' cannot be determined. Either 'Actual MTH'
doesn't exist, or there is no current row for a column named 'Actual
MTH'.
Any assistance with getting a greater understanding of the issue here would be appreciated.
Thanks
Try something like this for your measures:
YTD Actual = TOTALYTD(sum([Actual MTH]),'Dates'[date],ALL('Dates'[date]),"30/6")

Filtered LOD calculations in DAX expression Power BI

I have created LOD expressions in Tableau before which dynamically calculate when filters are applied. I am trying to achieve similar functionality in Power BI. I am very new to Power BI so I probably didn't ask google the right question. I simply want a column that shows the average sales over my "Filtered" data set. The closest I cam was using the Calculate(average(table[column]),All(table)) but that does not dynamically change when I apply the date slider. If I filter for 1/1 - 1/5 I want that average. Change the date range, the average should change.
Thank you.
You are probably looking for the ALLEXCEPT() function. In this case you would do something like
CALCULATE(AVERAGE(table[column]), ALLEXCEPT(table, table[date]))
that is basically saying that you want to remove all filters on the table except the filters on the date column.
CALCULATE(
AVERAGE(Table[Column]),
ALLSELECTED()
)