How do you change the data Color of a line chart in Power BI based on Slicer Selection - switch-statement

I have a table of selections that has no relationship and only serves to be a selector for a filter:
I then have this feed a slicer on my page so that when the user selectes a value, the following measure will evaluate (works great):
Metric Toggle = SWITCH(TRUE(),
SELECTEDVALUE(Metrics[Metric]) = "Current Ratio", MAX('FinancialData'[CurrentRatio])
,SELECTEDVALUE(Metrics[Metric]) = "Debt to Tangible Net Worth", MAX('FinancialData'[DebtToTNW])
,SELECTEDVALUE(Metrics[Metric]) = "Gross Sales", MAX('FinancialData'[GrossSales])
,SELECTEDVALUE(Metrics[Metric]) = "NetSales", MAX('FinancialData'[NetSales])
,SELECTEDVALUE(Metrics[Metric]) = "Current Portion of Long Term Debt", MAX('FinancialData'[CPLTD])
,SELECTEDVALUE(Metrics[Metric]) = "EBITDA", MAX('FinancialData'[EBITDA])
,0)
This measure drives a line chart. Is it possible to conditionally format the data line color on the chart for each selection? i.e If user selected "EBITDA", then line colour = Blue, If User Selected "Current Ratio", then Line Color = Red... etc

Deselect your Slicer value as below
Now add Metric to the Line Chart's Legend property and go to the Chart's property Data Color and you will find a list like below-
Now, select your specific colors for specific Metric value. Once you complete all the above setup, you will get your expected color for Line based on the Slicer selection.

Related

Tableau: Multiple columns in a filter

I have three numeric fields named A,B,C and wants them in a single filter in tableau and based on the one selected in that filter a line chart will be shown. For e.g. in filter Stages B column is selected and line chart of B is shown. Had it been column A selected then line chart of A would be displayed .
Pardon my way of asking question by showing a image. I just picked up learning tableau and not getting this trick any where.
Here is the snapshot of data
Create a (list) parameter named 'ABC'. With the values
A
B
C
Then create a calculated field
IF ABC = 'A' THEN [column_a]
ELSEIF ABC = 'B' THEN [column_b]
ELSEIF ABC = 'C' THEN [column_c]
END
Something like that should work for you. Check out Tableau training here. It's free, but you have to sign up for an account.
Another way without creating a calculated field. Just pivot the three columns to rows and your field on which you can apply filter is created. Let me show you
This is screenshot of input data
I converted three cols to pivots to get data reshaped like this
After renaming pivoted-fields column to Stages I can add directly this one to view and get my desired result.

How can I filter a slicer for one item through VBA?

My slicer contains over 100 cities and I'd like to filter the slicer through VBA on one city at a time (in order to print the region of the chart into a Powerpoint). The trouble is that I think I would have to list every other city and show them as "Selected = False". I need a code block where I only specify the city/cities I and the rest of the slicer options are "Selected = False" by default.
I've recorded the macro code below and I've searched the net for a solution to this problem but have come up empty-handed.
With ActiveWorkbook.SlicerCaches("Slicer_City")
.SlicerItems("New York").Selected = True
.SlicerItems("Chicago").Selected = False
.SlicerItems("Trenton").Selected = False
.SlicerItems("Atlanta").Selected = False
.SlicerItems("Houston").Selected = False
.SlicerItems("Los Angeles").Selected = False
' there are 100 more cities to list if I just wanted "New York" to be selected
'in the slicer
End With
I need code where I should only specify the selection (New York) and not declare every other city as "Selected = False".
The quickest way is to make the pivotfield of interest a pagefield, and then iterate through the items and set the .CurrentPage property of the PivotField to each in turn, as this automatically turns the other items to FALSE. If you don't want the PivotField in the Page Fields area, then you can still do this quickly by setting up a 'Master' PivotTable somewhere out of sight, putting the field of interest in the master as a PageField, connecting the Master PivotTable to PivotTable1 ('Slave') with a Slicer, and then changing the .CurrentPage property of the Master, which will then instantly filter the .Slave via the Slicer.
See my answer at VBA code to filter a pivot table based on the value in a Cell that has some efficiency tips for this kind of thing, as well as links to other answers containing code.

Enable "Display labels from the next field in the same column (compact form)

Is there a way to enable the option "Display labels from the next field in the same column (compact form) in VBA?
This only enables the "Show item labels in outline form"
ActiveSheet.PivotTables("Name of pivot table").PivotFields("Name of pivot field").LayoutForm = xlOutline
The syntax should be:
ActiveSheet.PivotTables("Name of pivot table").PivotFields("Name of pivot field").LayoutCompactRow = True

Tibco Spotfire, Remove text from cells

I am using Tibco Spotfire to display a list of checked reports.
I have a column "Validation statuts" with (oui , non ) values
I want color cells :
If statut is valid I Red color
If statut is invalid Orange color
And remove Text
Thank you
You have different options here such as using a graphical table with icons or a cross table but if I undesrtand correctly, if you only want to use a data table like this:
then you can create a calculated column as:
case [status]
when "oui" then " "
when "non" then ""
end as [color status]
and set the color for it

Moving date period filter in Excel 2010 pivot-table

Is it possible to set some kind of filter for a moving date period?
For example one of the DB views I'm trying to replicate in my pivot-table has this filter :
DATEDIFF(day, dateColumn, GETDATE()) <= 90
So basically I always want to display the last 90 days of whataver data there is in the cube table.
Is this possible?
The answer to this question is here :
http://blogs.socha.com/2010/05/sliding-date-ranges-with-excel-2010.html
Example for a moving period of 30 days :
Select a cell inside a pivot table bound to the cube so that the PivotTable tools are available
Click the Options tab on the ribbon under the PivotTable Tools section:
Click the Fields, Items & Sets drop-down in the Calculations section of this ribbon tab
Click Manage Sets… in the drop-down
Click New… and then Create Set using MDX…
Enter a name for this set in the Set name text box
Enter the MDX expression that defines the date range
Click OK
Filter(
[Date].[Date].[Date],
[Date].[Date].CurrentMember.Member_Value < Now()
AND [Date].[Date].CurrentMember.Member_Value >= DateAdd("d", -30, VBA![Date]())
)

Resources