How to calculate the index field for this table? - apache-superset

I have to calculate the following Index field on Superset?
Pivot Table Image
Data Definition:
Column B: Spend
Column C: Revenue
Column D: ROAS (this is calculated as follows: Column C/Column B)
Column E: ROAS Index (this is where i need the help, please find the calculation below)
Calculation for ROAS Index:
Divide the row level ROAS by the total ROAS. As per the screenshot, for the cell E38 the calculation would be D38/D53.
This calculation has to done dynamically, so the value can be calculated based on the filter selections.
Complexity:
Individual table with this view cant be used, as there are other dimensions on filters which will have impact on the value's granularity.
Thanks,
Prem
Tried writing calculated fields, but cant figure out the approach

Related

DAX & Power Query - Removing transaction line if sale is returned

First time posting, thanks in advance !
I have a simple sales table acting as a data source.
In this table I have all my dimensions and facts, the data model is not organized as a star schema.
I believe this question does not require the data model to be optimally built.
One column tracks the Sales Quantity and shows -1 if the item is returned.
In Power Query.
I wish, for all returns, to eliminate the line with the -1, but also the associated line with the +1 sale.
I do not wish to simply filter by the Invoice Number and remove it, as in the same invoice I may have other items who were not returned.
I wish to have in my final table only final records.
Thank you
Did not manage to identify a way to tackle the issue in Power Query as of yet.
Edit, addition of further context
Dataset abstract:
I would like to keep the green row and remove the yellow ones.
One invoice features three lines, two for one item being sold and returned, and one for an item being purchased for good. That latter one is to stay in the records.
[IMAGE : Excel version of relevant column in data base ]
https://i.stack.imgur.com/CiiiC.png
Because I do not know the exact nature of your data, I will give you a general solution for your problem, which will help you immensely.
First, I will transform your data into facts and questions. Then I will answer the questions depending on my experience analyzing many different datasets; last but not least, I will provide you with the solution.
Facts,
[Sales Amount Include Tax] column values for Return Sales are negative numbers because excel format negative numbers by including them with parentheses, as your data shows.
The Original Sale record and the Return Sale record must have the same values for these columns, which we will use to know the Original Sales record:
The absolute value for the [Sales Amount Include Tax] column.
[Invoice No], [Department], [Sub Dept], [Sub Dept GROUP], [Item Code] columns.
This point is critical because we will use these columns to know the Original Sales record.
Questions,
Is the Item code column value similar to the original sale row and the returned sales row?
My answer: It should be because you are returning the same item that the Item code column describes, but I am concerned that your data shows that the first two rows don't have the same Item code. Is it by mistake?
Is the Sales Quantity column always filled with -1, even if the original sales quantity was, for example, three pairs of shoes?
My answer: The Sales Quantity column should describe the number of items someone bought, so if I originally bought 2 things but didn't like them for a reason, I will return two items so that the column value will be -2.
If my above assumptions are correct, you need to do the following in the Power BI query:
1. Import your Sales table to Power BI. See this image that shows the test data I used.
2. When you import your data and see it in the Power Query Editor, you will see that the Sales Amount Include Tax column value shows minus rather than parentheses for Return Sales Rows, as you can see in this image.
3. Create a copy of your Sales table and Rename it to Returned Sales, then filter this table to include only [Sales Amount Include Tax] that are less than 0, as you can see in this image.
4. Filter the Sales table to include only [Sales Amount Include Tax] greater than or equal to 0, as you can see in this image.
P.S. Now comes the fun part :)
1. In Returned Sales table, add a custom column name it ReturnedSaleFlag, then give it a value of 1, as you can see in this image.
2. Change ReturnedSaleFlag column type to Whole number.
3. In Returned Sales table, transform [Sales Amount Include Tax] to an Absolute Value, as you can see in this image.
4. Now you need to return to the Sales table and merge it with Returned Sales table using multiple columns which are the column listed in the second point of the fact section, as the image shows. Also, see this link that describes how to Merge query based on multi columns.
5. Expanded the new Returned Sales column in Sales table and only select ReturnedSaleFlag column and make sure to remove the check from use original column name as a prefix, as the image shows.
6. Finally, all your previous hard work created a flag in your Sales table that will let you know the Sales record that had been returned. :)
7. Now you filter the Sales table to keep the records that only have null values for the new ReturnedSaleFlag column then remove this column, as the image shows.
8. In the end save and apply and analyze your Sales and your extra info in the Returned sales.
I hope I helped in a way; if so, please mark this as an answer and vote for it :)

Calculated column in Power BI based on relationship between 2 tables

Hi,
I'm trying to add a calculated column in my MergedTable table that will multiply the Time column by the sum of the indicator in the TeamLeave when the week ending dates and the name dates are the same but I'm not sure how or what functions to use(I've tried a number at this stage).
Could anyone provide me with assistance on this?
Thanks,
This:
'MergedTable'[Time] * CALCULATE(SUM('Team Leave'[Indicator]))
The CALCULATE is necessary to perform a context transition (turning the "current row" of 'MergedTable' into a filter that will propagate to the 'Team Leave' table).

How to show the total values of rows in a Matrix with number value having my columns values as percentage

I've started to manage PowerBi from a couple of weeks so i'm a little bit confused about some things.
My problem is that i need a Matrix in my dashboard with percent values but i want the total in number value because the total of a percent of row shows me always 100% and i dont know about the number i'm working
This is my Matrix with percentage values
This is how i want the total of row returns me but with the columns values ins percentage
I've tried to make a measure counting the values
COUNT(OPSRespuestas[answer])
After that turn off the total of rows and add this measure to the values in my matrix but this is what i get
This is my table after trying add a measure with the total
It returns me the total for each of the columns and not the total of all my rows.
These are the tables i'm working with
This my top header values
This is my left header values
The answer column is what i need to count
This is my relationship between this 3 tables although i have many more intermediate table aside from this 3 as you're going to see in the next picture:
My relationship tables
So finally what i need is that this matrix shows me the total of answer in percentage for each of departments and group of questions and then show me total by department but with number value
The problem you are experiencing has to do with context. Each row is seen as it own total population hence the 100% total. Each column in this row is evaluated against the total of that row to provide a percentage value.
In addition to adding a custom measure to replace the total, you could also consider computing a percentage against the grand total of all dimensions. This means that each cell gets evaluated against the the total of all rows and columns. In this ways the cell value would change compared to your first table but the row total does not evaluate to 100% anymore.
SUM ( [Value] ) / CALCULATE ( SUM ( [Value] ) ; ALL ( 'Your Table' ) )

How to sum a column filtered by a categorical column in the same table in Power Bi?

I'm trying to get a sum of my sales figures by the product category from the a column in the same table
The original data is on the attached image.
Original Data
And what I'm trying to get is attached also and I am having trouble getting the right numbers for the last three columns
Result
I have tried the following code:
Boots_Sales = CALCULATE( SUM(Sheet1[Sales]), FILTER(Sheet1,Sheet1[Product_Type]="Boots"))
I have found a solution to the above by making a measure instead of a column with the below formula:
boot1 = CALCULATE(SUM(original[Sales]),FILTER(original,original[Product type ]="Boots"))
This will have to do, I was trying to make a column because I wanted to do further calculations on the column but will just have to convert the measure into a column
Thanks

Adding a Total Column to a Matrix-Visual that only sums spcific columns

I have a table that has (simplified) the columns CustID, Action, Date
I then have a matrix visual that has Action as Columns, CustID AS Rows and Count(Action) as Values.
Now I need an extra column that sums only some of the Columns, not all like the Total. In Excel this is =SUMME(B11:K11), where K12 and K13 are the columns not to be summed.
Is this possible in PBI Matrix?
You can simply create a measure.
(new_measure_name) = 'table'[field to add] + 'table'[field to add]
After you create the measure you can add it to the matrix and double check you math that it adds up like you want.
Good luck!
my problem was, that I had a table column in the column section of the matrx visual. than, when I add a measure it is only available in drill, not as extra column. I solved it with pivoting that column and use the new columns in data section. than I can add measures to the data section and they get also new columns.
would be nice, if I could use the column section and add measures