Calculate doesn't show data for groups - powerbi

I am trying to filter the data by reading data from slicers and displaying the same in visual, I am able to write the formula but the problem is data is shown as the grand total instead of it should be split by group and finally shown as the grand total.
I need to show the data per area and total at the end.
var Week_selected = SELECTEDVALUE('Table 3'[FISCAL_WEEK])
Var EndDate = MAXX(FILTER('Table 3','Table 3'[FISCAL_WEEK] = Week_selected), 'Table 3'[Date].[Date])
var data = SUMMARIZE(FILTER(ALL('Table 3'), 'Table 3'[Date].[Date] >= DATE(YEAR(EndDate),1,1) && 'Table 3'[Date].[Date] <= EndDate),'Table 3'[Area],"mins",SUM('Table 3'[minutes]))
return
SUMX(data,[mins])
In above image value is repeated for areas aswell but I need 130729 to be split for area level and need to get the same as total.
any help is appreciated.
Thanks

Related

How to create line chart in PowerBI when the value is a text (Ok, Incorrect)?

Hi everyone,
I want to plot the line chart above in PowerBI based on the data that I have in column A,B and C. The challenge that I have is that the Values of the line chart only able to show as Percent of grand total instead of Percent of row/column total.
I'm still new to PowerBI, not sure any new measure that I can use to create the line chart above.
The line chart above is what I'm able to create in PowerBI, may I know what should I do to change the y-axis into percentage (percentage of OK for Mar + percentage of Incorrect for Mar = 100%) ? Any help will be greatly appreciated!
First create these below 3 measure-
total_student = DISTINCTCOUNT(your_table_name[Name])
ok_% =
VAR OK_COUNT = COUNTROWS(
FILTER(
your_table_name,
your_table_name[Answer] = "ok"
)
)
RETURN (OK_COUNT/your_table_name[total_student])
incorrect_% =
VAR incorrect_count = COUNTROWS(
FILTER(
your_table_name,
your_table_name[Answer] = "incorrect"
)
)
RETURN (incorrect_count/your_table_name[total_student])
Now convert last 2 measure as % and create your chart. Here below I have created everything for first 2 month from your sample data-
Note Your Month field need proper ordering for correct output.

need assistance\ideas on building what is hopefully a simple DAX measure

I am trying to figure out the DAX to create a new measure in an SSAS Tabular data model. An example of what I am trying to do is more easily shown than described. My SSAS Tabular dataset produces the following table. Cols A and B are from the stores table, Col C is a measure from the Sales table, Col D is a measure from the Products table, and Col E is C/D. This all works fine. Data has been mocked up in Excel to protect the innocent, but it is working in Power BI.
What I would like to do is add a new measure which calculates the Sales/Product at the state level and have that measure show for each store in that state, as shown below
Presumably I have to iterate over all rows and calculate the total sales/state and total products sold/state and divide those 2 to get the answer, but can't work out the DAX to get there. I have tried numerous combinations of
calculate(
sumx(...),
filter(
all(...),
...
)
)
to no avail.
You should use FILTER with ALL to manipulate a context(remove current context);
MesureSumStateLevel = calculate(SUM('Table'[Amount]),
FILTER(ALL('StoreStateTab'), 'StoreStateTab'[State] =
SELECTEDVALUE('StoreStateTab'[State])))
https://dax.guide/filter/
https://dax.guide/selectedvalue/
https://dax.guide/all/
Thanks for the tip. I originally tried that and dropped it because I couldn't get it working. I revisited this morning and solved it. Here is what I did:
State Ttl =
var trxYr = convert(SELECTEDVALUE(dim_date[Year]), INTEGER) //needed because Year is stored as text in the model
var trxMo = SELECTEDVALUE(dim_Date[Short Month Name])
var trxState = SELECTEDVALUE(fact_Sales[state])
Return
CALCULATE(
SUM(fact_sales[SalesAmt])
,all(fact_sales)
,year(fact_sales[SaleDATE]) = trxYr
,dim_Date[Short Month Name] = trxMo
,dim_Stores[state] = trxState
)

Power BI - Daily difference as a value and percentage

I have a power BI report that has the following
Date, City, Town, Order number,
What i would like to do is create a report that shows the total orders (volume) for every day (which i can do as that is nice and easy) but I also wanted to show the difference from the previous reported day (some days we dont have data, eg bank holidays etc)
I am new to power bi and my technical skills are not brilliant.
Thank you in advance to anyone who is able to provide a solution.
Welcome to SO. There are a few ways of achieving it - you can even calculate these values directly in Power Query - it all depends on your data model and how the report itself is constructed.
Below are two solutions that you might want to consider:
Solution 1 - calculated column
This adds a new column to your table. The overall concept is to find the maximum date that is less than the current row's date and retrieve the respective value.
Volume t-1 =
var ThisDate = Table1[Date]
var PrevDate =
MAXX(FILTER(ALL(Table1[Date]), Table1[Date] < ThisDate), Table1[Date])
var PrevValue =
MAXX(FILTER(Table1, Table1[Date] = PrevDate), Table1[Current Volume])
return
PrevValue
You can now use this new column to calculate the difference between the current value and the previous value, e.g.:
Difference = [Current Volume] - [Volume t-1]
Solution 2 - measure
mVolume t-1 =
var ThisDate = MAX(Table1[Date])
var PrevDate =
MAXX(FILTER(ALL(Table1[Date]), Table1[Date] < ThisDate), Table1[Date])
var PrevValue =
MAXX(FILTER(ALL(Table1), Table1[Date] = PrevDate), Table1[Current Volume])
return
PrevValue
Similar to the first solution, you can now calculate the difference between this measure and the [Current Volume] field. However, the final formula will depend on your report and visualization filters. For example, if you add a table with Dates column (daily frequency), you can add the following measure to your table visualization:
[mDifference] = MAX(Table1[Current Volume]) - MAX(Table1[Volume t-1])
I hope this is a good starting point - good luck!

Power BI: Count numbers by Today, and the count numbers of the previous years at the same date

I'm new to Power BI and DAX.
I want to show the total ID count of this year and the total ID counts of previous years at the same dates each of which is associated with a different Category_Number.
The below tables show the original data set (1st table) and the result table (2nd table) I would like to have.
enter image description here
enter image description here
Any ideas or suggestions will be greatly appreciated.
Thanks!
You want to filter and use SAMEPERIODLASTYEAR.
To get the values of one category you can do:
Category_Nbr 80 = CALCULATE(COUNTROWS(myTable),myTable[Category_Nbr] = 80)
for the value of this but for the previous year you could use your DATE TABLE if you have it, if not, use the automatic one. I'll assume you don't have one so use the automatic.
Category_Nbr 80 LY = CALCULATE([Category_Nbr 80],SAMEPERIODLASTYEAR(myTable[Effective_Date].Date))
With this you can do a comparison over time
Category_Nbr Count YoY = DIVIDE([Category_Nbr 80 LY]-[Category_Nbr 80],[Category_Nbr 80 LY])
You can just adapt the filter for other categories.
Consider having a look into Quick Measures really nice way to start learning DAX.
Below are two measures I created.
The Total_ID measure works well. It shows the total number of IDs that have the Category_Number =80 and Effecitve_Date < Today.
The Total_ID_LY measure shows the total number IDs that have the Category_Number = 70, but doesn't show the Effective_Date< The same data last year.
I want the Total_ID_LY measure to have two filters, Category_Number = 70 (80-10) and Effective_Date < The same data last year of today.
Any helps?
Thanks!
Total_ID = COUNT('myTable'[ID])
Total_ID_LY =
VAR CurrentCategory = SELECTEDVALUE ( 'myTable'[Category_Number] )
VAR PreviousCategory =
CALCULATE (
MAX ( 'myTable'[Category_Number] ),
ALLSELECTED ( 'myTable' ),
KEEPFILTERS ( 'myTable'[Category_Number] < CurrentCategory )
)
VAR Result =
CALCULATE (
[Total_ID],
'myTable'[Category_Number] = PreviousCategory
)
RETURN
Result

How can I refer to column created in var dynamically?

I have created a pareto analysis but the problem is that it's not dynamic because the rankx it's done in a calculated column in customers table in order of the sum of sales in an other table.
Now my #runningtotal is
CALCULATE([M-CY_Sales];FILTER(ALLSELECTED(CUSTOMERS);
CUSTOMERS[DAX RANK]<=MAX(CUSTOMERS[DAX RANK]));CUSTOMERS[Customer Number] <>BLANK();
'Detail Sales Report'[Total Actual Revenue - Base]>0)
where I use the calculated column with rankx CUSTOMERS[DAX RANK]. Can I make this measure dynamic? I was thinking to build a table with var and addcoloumn but I'm not able to do it. My actual problem is that I need this pareto dynamic because the filter for district does not function with static column.
I was trying to write something but I don't know how I could create what I want
#RUNNINGTOTAL2 =
var customerranked=ADDCOLUMNS(ALLSELECTED(CUSTOMERS);"ranking";[M-DAX RANK])
return
CALCULATE([M-CY_Sales];FILTER(ALLSELECTED(CUSTOMERS);
customerranked<=MAX(customerranked));CUSTOMERS[Customer Number]<>BLANK();
'Detail Sales Report'[Total Actual Revenue - Base]>0)
Obviously this is not correct. I hope you understand my problem. I need to refer a virtual column done with rankx in my measure running total
Sample data edited with measures: [here]: https://mega.nz/#!4t1y0AJI!XF2Vcejm6C50nnssQCS1bJEhnqIGiH1d-mIltVskRgE
While here is the PBIX file and it may work as you expected, but you should take a broom and sweep your model a little. To get it working just set up the relationship from District to Customer and then to Sales. Or even better, get rid of Districts table. You have that dimension in Customers table. I just slightly changed your measures to get it working but I would change them altogether. Probably you do not need to use FILTER function.
#RUNNINGTOTAL =
CALCULATE (
SUM ( 'Sales'[Revenue] ),
FILTER (
ALLSELECTED ( Customers ),
Customers[DAX RANK]
<= MAX ( Customers[DAX RANK] )
),
'Sales'[Revenue] > 0
)
Anyway I would start it from scratch.
Why do you have three tables? What is the purpose of table Districts. You can use the Districts form table Customers to slice Sales.
If you really do not accept corrected invoices and negative sales (ask yourself why), build a measure like that:
[Sales] =
CALCULATE (
SUM ( FactTable[Sales] ),
FactTable[Sales] > 0
)
And then refer to it in other measures. Check these posts to see differences of filtering:
DAX Calculate function with and without FILTER
Difference between CALCULATE(m, x=red) vs CALCULATE(m, KEEPFILTERS(x=red))
You may think of building a bridge table, between Customers and Sales, which will contain unique CustomerID of both tables. Dictionaries are updated with lag.
bridge =
DISTINCT (
UNION (
DISTINCT ( Sales[CustomerID] ),
DISTINCT ( Customers[CustomerID] )
)
)
Give it a shot: https://www.daxformatter.com/
It is indeed possible, and encouraged to define measures that calculates ranks and cumulative totals on the fly.
However, there are some visualization issues. It looks not possible to use a measure for x axis with "Line and clustered column chart". So it would not be possible to use the Rank measure for x axis. You may put Customer Number to x axis instead, however the chart will look badly with a categorical x axis. It will not fit in the screen and will require a long scroll to reach the right end. Practically, this will hardly work as a pareto chart.
On the basis of this observation, I suggest to use R / Python visual if possible. Here is an example with R visual.
library(dplyr)
library(ggplot2)
totalSales <- sum(dataset$SalesAmount)
dataset <- dataset %>%
arrange(desc(SalesAmount)) %>%
mutate(
CumulativeSales = cumsum(SalesAmount),
Rank = order(SalesAmount, decreasing = TRUE)
)
p <- ggplot(dataset, aes(x = Rank, y = SalesAmount)) +
geom_bar(stat = "identity", width = 1, fill = "#01b8aa")
ymax <- layer_scales(p)$y$range$range[2]
p <- p + geom_line(aes(y = CumulativeSales / totalSales * ymax),
size = 1, color = "#fd625e") +
scale_y_continuous(sec.axis = sec_axis(~ . * totalSales / ymax)) +
theme_bw()
p