I have a table like so:
Client Sales
Julie $100
Alex $1000
Ben $500
I want to create two sales buckets, 0-100$ and 100-1000$. I want to create a table that organizes the above data like so:
Bucket Total Sales
0-100$ $100
100-1000$ $1500
I am new to dax and I am at a loss on how to do this. This is what I have so far but it isn't spitting out the expected result:
sales = SWITCH (
TRUE,
'salestable'[sales]<= 100, 'salestable'[sales],
'salestable'[sales] > 100 && <= 1000, 'salestable'[sales],
)
Any help is much appreciated!
You need a calculated column or a measure lets create a calculated column inside the table as below. I suggest you to create a calculated column.
sales bucket =
IF (
'Sales Targets'[Target] <= 1000
&& 'Sales Targets'[Target] > 100,
"100-1000$",
IF ( 'Sales Targets'[Target] <= 100, "0-100$", BLANK () )
)
Related
I am new to Power BI and learning how to perform cohort analysis with DAX in Power BI. Is there any way to find out how many times (or if easier if a customer buys more than a certain threshold) their first month?
If I have the table Customers:
ID | DateOfFirstRegistration
And the table of orders:
ID | customerId | orderDate
Let me know if any more information is helpful!
EDIT: If possible, is it also possible to plot it in a matrix with customers in each row and month 1 through 3 in the columns?
Thank you
You can do something like this measure in a table visualization together with customer ID:
First Month Purchases =
VAR _registration =
SELECTEDVALUE ( 'customers'[DateOfFirstRegistration] )
RETURN
CALCULATE (
COUNTROWS ( 'orders' ) ,
DATESINPERIOD (
'orders'[orderDate] ,
_registration ,
1 ,
MONTH
)
)
I am using power BI and I would like to create a line chart which contains values from two tables (sales history and sales prediction). So for the past 12 months, the line should reprensent the sales history and for the next 6 months, the line reprensents sales prediction. Here is what the data looks like, lets say we are in June 2021:
I know there is a way to do it in DAX but I don't know how to do it by myself. Thanks a lot in advance for your help !
You can achieve this by
Delete any relationship between Calendar and the other two tables if there is any, as we are going to use DATESBETWEEN function to calculate
Create two metric like below, you might need to adjust the column names as per your project
Sales History Amount = IF('CALENDAR'[Date] <= TODAY(), CALCULATE(SUM('Sales History'[Amount]), DATESBETWEEN('Sales History'[Date], MIN('CALENDAR'[Date] ), MAX('CALENDAR'[Date]))), BLANK())
Sales Prediction Amount = IF('CALENDAR'[Date] >= TODAY(), CALCULATE(SUM('Sales Prediction'[Amount]), DATESBETWEEN('Sales Prediction'[Date], MIN('CALENDAR'[Date] ), MAX('CALENDAR'[Date]))), BLANK())
Add these two metrics in the table and use the Date from the Calendar table as X axis.
Format the first metric to solid line, and dash line for the second
Calendar should be linked to your tables.
Prediction Amount =
VAR lastSalesDate = MAX('Sales History'[Date])
VAR currentPredictionAmnt =
CALCULATE(
SUM('Sales Prediction'[Amount])
,KEEPFILTERS('CALENDAR'[Date]>lastSalesDate)
)
RETURN currentPredictionAmnt + SUM()
Sales Amount =
SUM('Sales History'[Amount])
I am looking for a solution of this probably simple problem. I have two tables in Power BI: Inventory and Sales:
Inventory Sales
Item Title Item Quantity
123 Soap 124 5
124 Detergent 123 8
125 Toothpaste
126 Tooth brush
How can I make a table that lists items not sold. I.e. I need to return:
Item Title
125 Toothpaste
126 Tooth brush
I would add a Measure to the Inventory table, e.g.
Item Quantity = 0 + SUM ( Sales[Quantity] )
Then I would add that Measure to the Visual level filters for your table visual, and set the filter to:
Show items when the value:
is
0
You could create a calculated column:
=IF(LOOKUPVALUE(Sales[item];Sales[item];Inventory[item]);BLANK();1)
and then filter for this column = 1
Or you could do this:
=IF(LOOKUPVALUE(Sales[item];Sales[item];Inventory[item]);BLANK();[title])
If you use this columns on your axis in a visual/table, only items not sold will show up.
Or you could use create a measure like this, assuming there is a relationship between the two tables on Item:
Products not being sold :=
IF (
ISBLANK (
CALCULATE (
DISTINCTCOUNT ( Inventory[item] );
FILTER ( Sales; Sales[item] = [item] )
)
);
1;
BLANK ()
)
if you add this measure to your visual/table only items not sold will show up
I am working on getting the amount of new sales and lost sales with regards to sales previous year and sales year to date. I am trying to show this in a table and then filtering that table with a year slicer.
Below are the formulas that i have used:
SalesPY = CALCULATE(SUM(SalesData[Value]),SAMEPERIODLASTYEAR('Calendar'[DateKey]))
SalesYTD = TOTALYTD(SUM(SalesData[Value]), 'Calendar'[DateKey])
NewSalesUppdate = SUMX(VALUES(SalesData[CustomerName]),IF([SalesYTD] > 0 && [SalesPY] = 0, [SalesYTD]))
LostSalesUppdate = SUMX(VALUES(SalesData[CustomerName]),IF([SalesYTD] = 0 && [SalesPY] > 0, -[SalesPY]))
LostSalesOld = IF([SalesPY] > 0 && [SalesYTD] = 0, -[SalesPY])
The NewSalesUppdate formula works as it should and sums up correctly. However LostSalesUppdate does not work, despite having pretty much the opposite formula compared with NewSalesUppdate. It seems like the IF statement never becomes true. That is strange because the LostSalesOld formula shows the right value, but it does not show the total.
All tips are appreciated!
Sample Data:
Current Result:
Notice how customer A had no YTD sales. The LostSalesOld shows -85000 in sales, but nothing is reflected in the total. The LostSalesUppdate shows nothing at all.
Desired Result:
Now one of the lost sales columns (doesn't matter which) has a value for customer A, and a total
Focusing on LostSalesUppdate, the issue is one of context. Your measure is saying "For each customer name in the SalesData table, show me last year's sales negated if they had sales last year and none this year".
The problem (and I'll admit it is subtle), is that because there are no sales for Customer A this year, Customer A is not in the SalesData table as far as this measure is concerned. Therefore, the rest of the formula is ignored.
What I would recommend is adding a separate table with a list of customers, similar to your date table (one row per customer). Then, update your LostSalesUppdate formula so that instead of pulling CustomerName from SalesData, it pulls it from your new customer table.
LostSalesUppdate =
SUMX (
VALUES ( Customer[CustomerName] ),
IF ( [SalesYTD] = 0 && [SalesPY] > 0, - [SalesPY] )
)
I'm trying to create a line graph in PowerBI. What I am trying to plot is somewhat complex.
I have the following tables:
Staffing - this table describes staffing for every employee in the company. By "staffing" I'm referring to how their time is allocated. For example, Employee #7 is staffed in "Chicken Manufacturing" with a StartDate of 1/1/2016 and an EndDate of 1/10/2016
EmployeeID Project StartDate EndDate
5 Cutting Lemons 12/1/2015 12/31/2015
5 Chicken Manufacturing 1/1/2016 1/10/2016
6 Fishing Lobsters 1/2/2016 1/5/2016
7 Chicken Manufacturing 1/5/2016 2/1/2016
8 Drinking 2/1/2016 null
I also have a standard Date dimension as well as an Employees table and a Project table. The Employees table has a row for every employee and the Project has a row for each activity.
I am trying to create a line graph that has dates on the x-axis and the line will show me how many employees are active at the given date. So for dates 12/1/2015 - 1/10/2016 Employee 5 should be counted as "Staffed" but on 1/11/2016, he should not be included in the total.
What I'm actually trying to do is calculate Availability and by that I mean, how many Employee hours are available on each day (I have a project called Available) so ultimately I will want to count the number of Hours rather than employees, but I think if I can get to work with counting employees, I shouldn't have too much trouble multiplying number of employees by 8 hours per day.
Try something like this:
Count of Emp =
CALCULATE (
DISTINCTCOUNT ( Employee[EmployeeID] ),
FILTER (
Staffing,
[StartDate] <= MAX ( 'Date'[Date] )
&& (
[EndDate] >= MAX ( 'Date'[Date] )
|| ISBLANK ( [EndDate] )
)
)
)
It is not tested but should work as long as you have relatinship between Employee - Staffing. Also be sure to use your date column in the Axis setting.
Let me know if this helps.