Dynamically format multiple columns (round to two decimal places) - mdx

I am new to MDX, but from what I've read, the way to format the output for a number column is to modify the FORMAT property on the cube in which it's defined. I don't have access to do that, so I was looking for a way to do it dynamically in the query, and I found this page, which does the following:
with
cell calculation [Round2]
for '[Measures].[MyNumber]'
as [Measures].CurrentMember
, format_string = "#,#0.00"
select
non empty {[Measures].[MyNumber]} on columns
, non empty ([MyDim].[MyDescription].[MyDescription]) on rows
from
[Cube]
;
I've got this working. However, I have multiple columns that will need this same formatting applied. I've tried adding more columns in the for clause, like for '[Measures].[MyNumber1], [Measures].[MyNumber2], ...', as well as other variants, but nothing is working except the "single-column syntax".
Questions:
Is there a way to apply formatting like this in a concise manner to
multiple columns, without having to repeat the cell calculation
syntax for every column needing the formatting?
Is there a better approach to dynamically format the columns
(without modifying the properties defined in the Cube).

Related

MDX - Display the labels/values for dimensions for this MDX query

Usually I display a value for dimensions by using the CurrentMember.Value/caption as as an alias.
For the following query this breaks with an error along the lines of
'The hierarchy [Measures] appears in more than one axis or in an axis/axes and a slicer too'.
Which I understand.
So how do I edit/expand the query such that I see the book values on rows (normally achieved with
'WITH Member [Measures].[Book_Label] AS [Book].[Book].CURRENTMEMBER.MEMBER_CAPTION'
and the column dimension values along the top?
(Excel image below, values white color'd out as on client site.)
SELECT
NON EMPTY ([Ccy].[Ccy].[Ccy])
ON COLUMNS ,
NON EMPTY
([Book].[Book].[Book])
ON ROWS
FROM [TraderCube]
WHERE
([Date].[Date].[ALL].[AllMember].[2019-12-12],[Measures].[JTD.SUM])
I have made more progress however this comes out staggered duplicating the row / book label at each repeated currency.
Does anyone know how I would:
1) Get the currencies along the top?
2) Have one row / book label per row?
WITH
Member [Measures].[Book_Label] AS [Book].[Book].CURRENTMEMBER.MEMBER_CAPTION
SELECT
NON EMPTY (HIERARCHIZE(([Ccy].[Ccy].Members, {[Measures].[Book_Label],[Measures].[JTD.SUM]}), POST))
ON COLUMNS,
NON EMPTY (HIERARCHIZE([Book].[Book].Members, POST))
ON ROWS
FROM[TraderCube] WHERE ([Date].[Date].[2019-12-13])"
As an update for anyone who comes across this thread/question, for me I am writing a C# layer that translates simple user words and constructs MDX. I query the remote cube and then I return a 2D array. Up until now I constructed the headerRow etc myself and I returned the row dimension labels using the MDX itself.
I have now discovered that metadata is available on the AdomoClient libraries I am using.
This tutorial has inspired me:
https://www.codeproject.com/Articles/28290/Microsoft-Analysis-Services-2005-Displaying-a-grid
It's not a direct answer to my query of getting all of the labels in MDX but it will mean I can construct my headerRow (may be more than one row as seen in Excel pivots) and populate my row labels differently using the positions property of each Axes on the set (Axes[0] is columns, Axes[1] is rows) and the Positions property has a member property too.

Coloring Excel Cell based on a table condition

I am going through the users of a system and reviewing if they have appropriate role names. I then completed an excel table that looks abit like this:
I'm trying to turn the table into a more readable format. I have made a pivot that looks like this:
But I'm not sure how to highlight the cells to reflect the 'Access Appropriate? Yes/No' column. Ideally, it should be colored yellow if the 'Access Appropriate?' = 'No'. I'm thinking of using VBA, but was wondering if there is an easier solution using formulas or pivot table?
Your pivoted data isn't an actual excel pivot table, is it? I know what the x mean, but where do they come from?
Two possibilities come to mind if you want a flexible setup without VBA, aswell as an rather simple VBA-approach that uses an UDF.
Quick'n'dirty (really dirty) would be to
use 1/0 instead of yes/no (you could write that into a helper column with an if-function)
create a new pivot with ROLE_NAME for columns, USER_NAME for rows and SUM or MAX of [Access appropriate] for values
that means: instead of your x you will end up having 1 and 0. Empty cells will still be empty.
conditional format the value-range, e.g. If 1 then green If 0 then yellow if "" then Nothing
Alternatively, you could build your output-table with formulas like INDEX, MATCH and VLOOKUP-formulas.
An additional Key-Column with USERNAME&ROLE_NAME will be needed
conditional format the value-range
VBA: Provided your Rows are distinct a user defined function could do the following
read data into a recordset IF that hasnt been done already (meaning: declared on module-level, the first function call will fill it)
access the data in your recordset with a Recordset.Filter based on your input parameters - USERNAME and ROLE_NAME, in your case
output a certain Field.Value based on your input parameter - Access Appropriate in your case
conditional format the TRUE/FALSE values you get (since this can't easily be done inside an UDF)

Conditional formatting comparing two adjacent columns for every other column

It's easy to do conditional formatting that compares 2 columns, e.g.: =$A1=$B1. But what if I also want to compare C and D, but NOT B and C? Ideally, I'd like to do this with a single conditional formatting formula since I have many columns, but I'll settle for VBA if necessary (I'm just unfamiliar with conditional formatting in VBA).
NOTE: I've tried some variations of =AND(MOD(COLUMN(),2),A1=B1), but that hasn't worked.
NOTE 2: Here's some more specifics: Basically I'm comparing data in two nearly identical tables, and I want to highlight any differences. So for example, each table has a "Study_ID" column, and I want to view those side by side on a new sheet, e.g. in Columns A and B, highlighting unmatched cells in both columns. It would be easy to say =$A1:$B1 and apply to =$A$A:$B$B. But I'm also viewing "Name" side by side, e.g. in Columns C and D. I could add a new formula =$C1:$D1. But since the source tables have like 20 columns, that would require like 20+ formulas. I'd prefer one.
Thanks!
The image below was accomplished using multiple formulas (=$A1<>$B1, applied to =$A$1:$B$4, and =$C1<>$D1, applied to =$C$1:$D$4)
Edit: Figured out a single formula that will do it:
=A2<>OFFSET(A2,,IF(MOD(COLUMN(),2)=1,1,-1))

Need a simple search function to display most common value in a column. (with ambiguous choices)

I have a very large array of data with many columns that display different outputs for the values presented. I would like to add a row above the data that will display the most common occurring value or word below.
Generally I would like to have each top of the column (right under the column label in row 1) have the most common value below. I will then use this value for various data analysis functions!
Is this possible, and if so, how? Preferably this will not require VBA, but simply a short code in the cell.
One caveat: The exact values may vary, so there is no set list where I can say "it will be one of these."
Any ideas appreciated!
Try a series of =COUNTIF(A:A,"VALUE TO SEARCH") functions if you want to stay away from VBA.
Otherwise, the best method would be to iterate through each column via VBA. With this method, you can even count the "varying" values and return the count and/or the value itself.
http://www.excel-easy.com/examples/most-frequently-occurring-word.html
This is a single formula you would write at the top of each column. Does not require VBA. You can replace the set range to an entire column, such as (A:A) instead of (A1:A7).
If you mean an array as in a data type, it could work differently but it depends what you're trying to do.
With data from A3 through A16, in A2 enter:
=INDEX($A$3:$A$16,MODE(MATCH($A$3:$A$16,$A$3:$A$16,0)))
This will work for text as well as numbers. Adjust this to match the column size.

Count unique string variants

There could be quite a simple solution to this, but I am trying to find the number of times a unique variant (i.e. non-duplicates) of a string appears in a column. However this string is only part of the text contained in a cell, and not the entire cell. To illustrate:
EuropeSpainMadrid
EuropeSpainBarcelona
AsiaChinaShanghai
AsiaJapanTokyo
EuropeEnglandLondon
EuropeSpainMadrid
I would like to find how many unique instances there are of a string that contains "EuropeSpain". So using this example, I would find that a variant of "EuropeSpain" appears only twice (given that the second instance of "EuropeSpainMadrid" is a duplicate).
A solution to this is to use pivots to summarise the data and remove duplicated; however given that my underlying dataset changes often this would require manual adjustments and corrections. I would therefore like to avoid adding any intermediate steps (i.e. PivotTables, other data sets etc) between my data and the counts.
UPDATE: I now understand to use wildcards to solve the first part of my question (counting the occurrences of "EuropeSpain"), however I am not yet clear on the second part of my question (how to find the number of unique occurrences).
Is there a formula or VBA code that could do this?
Using wildcards:
=COUNTIF(A1:A6,"="&"*"&C1&"*")
For without VBA but with some versatility, I suggest with Text in ColumnA (labelled), ColumnB labelled Flag and EuropeSpain in C1:
=FIND(C$1,A2)
in B2 copied down.
Then pivot A:B with Flag for FILTERS (and 1 selected), Text for ROWS and Count of Text for Sigma VALUES.
Apply Distinct Values if required (and available!), alternatively a formula of the kind:
=MATCH("Grand Total",E:E)-4
would count uniques.