Need to create a Bucket using a Calculated Column - Power BI - powerbi

Below is how my data looks
enter image description here
I need to create a Calculated ColumnF(Bucket) based on Date selection which I need to use in a Barchart (X- Axis)
For Example DateSelected = Jan1 & Jan2, Client = Client1 then Sessions should be = 11(1+10) and Bucket = 11 to 20
I am able to achieve this by creating Calculated Measure but not calculated Columns
enter image description here
Is there a dynamic way in Power BI that will update the column based on user selection

Related

PowerBI DAX Query - undo filter slicer on certain values based on expression

I have below table structure:
enter image description here
here I want to put a date slicer in Power BI to filter on dates and return the count of total rows as total in the card as shown below:
enter image description here
simple, the only twist is that I want to have the total of hybrid car added at all times.
i.e.
Brands before 5/25/2020 = 4 Hybrid + 1 Electric = 5
Brands before 12/5/2020 = 4 Hybrid + 3 Electric = 7
I have found a solution, which is creating a view in my database, which jus holds the number count of hybrid car (select count(*) from table where cartype = 'hybrid') and using it to sum with filter rows in power bi - but I am looking for a solution completely in Power BI DAX query.
any measure I have tried to create in power bi is filtered by date slicer and so doesn't work.
Create these measure:
TOTALROWS = COUNT('cars'[brand])
ELECTRIC_NUM = CALCULATE([TotalRows],('cars'),'cars'[cartype]="ELECTRIC")
HYBRID_NUM = CALCULATE([TOTALROWS],ALL('cars'),'cars'[cartype]="HYBRID")
TOTALBYBUSINESSLOGIC = CALCULATE([ELECTRIC_NUM]+[HYBRID_NUM])
Now use the last measure (i.e. TOTALBYBUSINESSLOGIC) to be used in your Card to display the total, Notice the expression diffrence between ELECTRIC_NUM and HYBRID_NUM
(In HYBRID_NUM I have used ALL, All will have it bypass the Date Slicer filter) whereas ELECTRIC_NUM will only proivde sum of rows falling in the active date sliver range.

PowerBI: Get values from a column based on a measure filter

I have a PowerBI dashboard that contains casino guest information, including their latitude and longitude coordinates. The dashboard allows a user to input a zip code and select a radius around that zip (slicers). When doing so, it filters the table of casino guests to only those with a distance (measure) less than or equal to the radius chosen. I used this distance measure and logic to create another measure "InRadius" that would show 1 or 0 depending on if the given guest is within the radius. then used this "InRadius" measure as a filter for my table, as well as other visuals. everything works fine, except I am wanting to add a "between" slicer that will filter guest's ADW Range and I am unable to filter this slicer by my measure "InRadius", therefore my min and max values for ADW in the slicer, do not accurately reflect the ADW ranges for guests filtered in my table. Is there any way for me to get around this? Is it possible to create a new measure that I could use specifically for this slicer? Is it possible to filter a slicer by only the values present in an already filtered table? In general, I am just wanting to create a slicer that filters a columns values based on a measure's value, but can't figure out how to go about accomplishing it.
some codes I have tried while creating a new measure but haven't given desired result:
InRadiusADWFilter = IF([InRadiusPatron]=1, VALUES(TF_MapRadius[ADWNet]))
InRadiusADWFilter = FILTER(VALUES(TF_MapRadius[ADWNet]), [InRadiusPatron]=1)
InRadiusADWFilter = CALCULATE(VALUES(TF_MapRadius[ADWNet]), [InRadiusPatron]=1)
Here is my code for my measure distance:
// Haversine/great-circle distance calculation adapted from Stack Overflow: https://stackoverflow.com/questions/27928/calculate-distance-between-two-latitude-longitude-points-haversine-formula
VAR __latSelected = SELECTEDVALUE('TF_MapRadius'[maplat])
VAR __lonSelected = SELECTEDVALUE('TF_MapRadius'[maplong])
VAR __radius = 3956
VAR __multiplier = PI()/180
VAR __latDiff = (MIN('Selector'[Latitude])-__latSelected) * __multiplier
VAR __lonDiff = (MIN('Selector'[Longitude])-__lonSelected) * __multiplier
VAR __formula1 =
SIN(__latDiff/2) * SIN(__latDiff/2) +
COS(MIN('Selector'[Latitude]) * __multiplier) * COS(__latSelected * __multiplier) *
SIN(__lonDiff/2) * SIN(__lonDiff/2)
VAR __formula2 = 2 * ATAN(DIVIDE(SQRT(__formula1),SQRT(1-__formula1)))
VAR __distance = __radius * __formula2
RETURN __distance
here is my code for the measure "InRadius":
InRadiusPatron = if('TF_MapRadius'[Distance2] < Radius[Radius Value],1,0)
I've created dummy table that represents my filtered table:
ID
PatronName
ADWNet
Distance
InRadius
1
Smith, John
325,555
5.2
1
2
Jobs, Steve
200
7.0
1
3
Jeter, Derek
90,000
10.1
1
4
Jordan, Michael
-2,567
14.5
1
If you have measure that returning 1/0 (for example InRadius), then you can filter your visualization (select it and go to filter pane).

How to create a calculated column in PowerBi to achieve the below?

I have the data in the following format.
CompanyID Company Name
1 Nike
2 Adidas
3 Puma
I need to create a column and use it in X axis of a line chart or any visual for that matter in such a way that if a user from Nike logs in, in the visual he should "Nike" instead of companyID. But, for others he should the CompanyID.
Just add a new conditional column in Power Query or a computed column in DAX and use it instead of Company Name.
With Power Query:
With DAX:
Custom Company Name DAX = IF(Companies[CompanyID] = 1, Companies[Company Name], CONVERT(Companies[CompanyID], STRING))
Report data:
Report visuals:

Power BI Percentage of Total

I'm trying to get a column to display in a table that will display Users as a percentage of total users. I can get this to work using a calculated column but this does not work with a slicer that allows the user to filter the data. It always calculates against the total of the unfiltered column and not the user filtered column.
I think I need a measure but I can't figure out how to do it.
What I want is :
Users Value / Sum(Users Value Column)
Any Suggestions?
Solved! This was my solution
Measure =
Selectedvalue('dataName'[Users])
/
Calculate(sum([Users]),allselected('DataName'[column]))

How to add Filter to Slicer to display the calculated Measure based on selection using Power BI

I am totally new to Power BI and struggling with Slicer. I have the below requirement:
I have 4 columns Starting From, Destination, Distance KM. For this, I need to add a slicer. If the user clicks on Distance KM, then the chart has to be updated with Distance KM values. Now here comes the trick. I also want to display a column Distance in Miles based on the Distance KM calculation(the KM has to be displayed in Miles). So, whenever user clicks on Distance KM(in slicer), it should show the chart with KM data, if the user clicks on Miles(in slicer), then the chart should be populated with Miles information. I need to do this using slicer in power bi. Trying to achieve this since a while but couldn't get through it.
Please help me out
You only list three columns after stating your data has four, but I believe this should work:
You need to create a new table for the slicer. Within the Home tab select "Enter Data". Enter the values you want to be able to select from (I named the table DistanceSlicer). Load that table and create a slicer with it.
Now you can create a new measure based on this slicer selection. Within the Modeling tab select "New Measure".
SelectedMeasure =
IF (
VALUES ( DistanceSlicer[Measure] ) = "Kilometers",
SUM ( Table1[Distance KM] ),
SUM ( Table1[Distance Miles] )
)
Now use this measure in your table/chart and it should update based on your slicer selection.