Rename field parameter - powerbi

Here's teh pbix file https://1drv.ms/u/s!Amd7BXzYs7AVlm0j7IBWB7EZWKIM?e=LTrZMe
I use field parameter 
Slice by = {
    ("Brand", NAMEOF('Product'[Brand]), 0),
    ("Category", NAMEOF('Product'[Category]), 1),
    ("Color", NAMEOF('Product'[Color]), 2),
    ("Continent", NAMEOF('Customer'[Continent]), 3),
    ("Country", NAMEOF('Customer'[Country]), 4)
}
I add a slicer Month-year 
I'd like when I select for the slicer monthyear for example feb 2020, I'd like that in the matrix Brand and category will be renamed as Brand feb 2020 and category feb 2020, is there a way to do it please?

Power BI will not let you dynamically change the name of a label in a column. You could either include the year month as a column as you would in a matrix table.
Or you could add a measure that shows the selected value and put that in a card or multi card visual above the table. The measure would be defined like this:
TimeSelectionLabel =
IF ( HASONEVALUE ( Date[Month] ), SELECTEDVALUE ( Date[Month] ), "" )

Related

Dax for last sales date by ProductID in new custom column

I have a table with this information
ProductID
Date sold
1
01/01/2022
1
02/01/2022
2
01/01/2022
2
03/01/2022
2
04/01/2022
I now want to add a new column to the table in Power BI, and set a binary flag if that's the latest sales date for the ProductID. So, my expected output is this:
ProductID
Date sold
Latest sales date for product
1
01/01/2022
0
1
02/01/2022
1
2
01/01/2022
0
2
03/01/2022
0
2
04/01/2022
1
How do I write the DAX for column latest sales date for product to get this output?
this is the measure :
Latest sales date for product =
VAR _slct =
SELECTEDVALUE ( 'Table'[Date sold] )
RETURN
IF (
CALCULATE (
LASTDATE ( 'Table'[Date sold] ),
ALLEXCEPT ( 'Table', 'Table'[ProductID ] )
) = _slct,
1,
0
)
or if you want to add as a calculated column
Latest sales date for product column =
IF (
CALCULATE (
LASTDATE ( 'Table'[Date sold] ),
ALLEXCEPT ( 'Table', 'Table'[ProductID ] )
) = 'Table'[Date sold],
1,
0
)
With this measure
Latest sales date for product = MAX('Table'[Date sold])
you'll get

How to create sales buckets in dax/powerbi?

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 () )
)

I can not create a table in oracle apex

I am trying to create the following table on the apex website but it gives me an error .I tested this in SQL plus and it worked perfectly.
CREATE TABLE job_grade
   (Grade_level varchar(2) not null,
    lowest_sal number not null,
    highest_sal number not null);
INSERT ALL
    INTO job_grade
    VALUES ('A', 0, 1000)
    INTO job_grade
    VALUES ('B', 1001, 2000)
    INTO job_grade
    VALUES ('C', 2001, 3000)
    INTO job_grade
    VALUES ('D', 3001, 4000)
    INTO job_grade
    VALUES ('E', 4001, 5000)
SELECT * FROM DUAL;
output:
ORA-00911: invalid character
ORA-06512: at "SYS.WWV_DBMS_SQL_APEX_210200", line 673
ORA-06512: at "SYS.DBMS_SYS_SQL", line 1658
ORA-06512: at "SYS.WWV_DBMS_SQL_APEX_210200", line 659
ORA-06512: at "APEX_210200.WWV_FLOW_DYNAMIC_EXEC", line 1829
4. highest_sal number not null);
5. INSERT ALL
6. INTO job_grade
7. VALUES ('A', 0, 1000)
8. INTO job_grade
The issue is with the SQL Workshop in apex. This does NOT work like sqlplus or sqldeveloper. If you click "run" apex will try and run everything as a single statement and this fails if there are multiple statements.
But don't worry, there is a simple workaround. Highlight the statement with the mouse and then click run. That will run only the highlighted statement. So in this case, highlight the CREATE TABLE statement and run it, then highlight the INSERT ALL statement and run it.
For running multiple statements, use "SQL Script" instead.
Do as #Koen said.
Alternatively, run a single CTAS which "combines" CREATE TABLE and INSERT INTO:
SQL> create table job_grade (grade_level, lowest_sal, highest_sal) as
2 select 'A', 0, 1000 from dual union all
3 select 'B', 1001, 2000 from dual union all
4 select 'C', 2001, 3000 from dual union all
5 select 'D', 3001, 4000 from dual union all
6 select 'E', 4001, 5000 from dual;
Table created.
SQL>

Custom Date Table Drill-down Issue Power BI

Using the built-in Power BI date table, you are able to drill down from year -> Qtr -> month effortlessly, as shown below:
The date table used to generate the drill-down figure above:
DAX Formula: Cal = CALENDAR(MIN(Data[Date]),MAX(Data[Date]))
I would like to maintain this drill-down capability for the following custom date table:
Dates =
GENERATE (
CALENDAR ( DATE ( 2016, 10, 1 ), DATE ( 2025, 10, 1 ) ),
VAR currentDay = [Date]
VAR year =
IF ( MONTH ( currentDay ) >= 10, YEAR ( currentDay ) + 1, YEAR ( currentDay ) )
VAR quarter =
IF (
MONTH ( currentDay ) >= 10,
1,
IF ( MONTH ( currentDay ) <= 3, 2, IF ( MONTH ( currentDay ) <= 6, 3, 4 ) )
)
VAR month =
IF (
MONTH ( currentDay ) >= 10,
MONTH ( currentDay ) - 9,
MONTH ( currentDay ) + 3
)
RETURN
ROW ( "year", year, "quarter", quarter, "month", month )
)
It seems that the moment I mark "Dates" as the date table, I am unable to implement the built-in drill-down capability. I tried adding a date hierarchy, but cannot seem to control the order of the drill-down. For example, the visuals display month initially, and then "drill-down" to year, and finally to quarter. (this order doesn't make sense to me and I can't seem to change it). I need to be able to go from year -> quarter -> month, as before. I cannot use the default date table because I am using fiscal dates.
This is the result I am getting:
Please let me know if anything needs clarification, thank you!
I am able to sort in custom date table(with different fiscal year), Please find the snapshot attached for your reference.
I have used the power query to create a custom date table ( you can find the code here https://radacad.com/create-a-date-dimension-in-power-bi-in-4-steps-step-2-fiscal-columns)
we just need to change the startdate, enddate and StartOfFiscalYear(custom fiscal month).
Try and let me know
You have defined your date hierarchy as Date > year > month > quarter, per your screenshot. The order of the fields in the hierarchy defines your drill order. You do not need to define a hierarchy, you can simply drop fields ad-hoc into the field well for any visual. But if you're using a hierarchy, you must define it in the correct order:
year > quarter > month > Date
You can see the order in your hierarchy:
You can reorder these fields by clicking and dragging them within the hierarchy, or by right clicking and selecting "Move up" or "Move down":

POWER BI - Create a measure to compare Forecast vs Sales

Create a measure to compare forecast vs sales in power BI.
The logic is that at the beginning of Jan. 2018 it is forecasted the sales for the whole year and the amount of pcs sold in Jan. 2018 is only known in Feb. 2018 (next month's file). As an example, we are in Nov. 2018 and it is known how many pcs were sold in the previous months. I want to create a table to compare forecast vs sales.
My dataset looks like the figure below. It is marked in red the historical data.
An example of a power BI matrix that I am trying to create by dividing forecast by sales
It looks like you need to normalize your data source. This may look something like:
Now you can create some measures. Create a Forecast Qty measure:
Forecast Qty:=CALCULATE (
SUM ( SourceTable[Qty] ),
SourceTable[Type] = "Forecast"
)
A Sold Qty measure:
Sold Qty:=CALCULATE (
SUM ( SourceTable[Qty] ),
SourceTable[Type] = "Sold"
)
And a Sales % Forecast Measure:
Sales % Forecast:=DIVIDE (
[Sold Qty],
[Forecast Qty],
BLANK()
)
Now you can lay out your visualisation as you choose. For example: