SQL Calculate Percentage of one Column to Another - sccm

I want to find out what percent a number is of another number. I'm new to SQL and I'm confused on how to go about this. I've been following videos and tutorials with no luck. I want this to work like below.

It looks like you are trying to calculate the percentage of integers. You need to cast the integers to a Datatype that supports Decimals. Try this:
select cast(pfe.TotalManagedSystem as Float) / cast(pfe.AllSystems as Float) as Percentage;
Or:
select cast(pfe.TotalManagedSystem as decimal) / cast(pfe.AllSystems as decimal) as Percentage;

Related

Total less available = Remaining Formula in Power Query

I have a bunch of statistical data that I have chopped up and pieced together in power query. In looks like there is category missing from the Database. To fill in the gaps I am trying to take the grand totals which are correct (red), subtract from that what I know to be correct, with the remaining numbers giving me my answer (orange).
The correct data starts with I1, I2, I3, I4, so possibly a grand total of these, by state.
At the moment this is filled by the following formula in excel;
=E53-SUMIFS($E$5:$E$44,$B$5:$B$44,B45,$C$5:$C$44,C45,$D$5:$D$44,D45)
Any help with how the heck I can do this in power query. I realise I cant use the same formula but any ideas would be much appreciated. I can change the text in red to total if that helps in some way?
Thanks
Here's one potential way. If you start with your spreadsheet set up similar to this:
I only used a subset of your StateIDs from your example and generated my own Values for this example. And the figures in the Available column would be from your red section.
Then add the table from the spreadsheet to Power Query (in Excel, you would click on the table and then Data > From Table/Range > Select My table has headers and click OK).
In Power Query:
You'll probably have to change the TimeID type to date if you want to use the dates for anything, because it will probably come in as date-time type--I won't use the dates here though, so you could skip changing the type (otherwise, right-click the TimeID column > Change Type > Date)
Then use Group By to aggregate values and set the stage for the calculation you want (select the StateID > Group By > and setup the groupings like below and click OK)
You should see something like this:
Then add a new column with your calculation (Add Column > Custom Column > Set it up like below and click OK)
You should see something like this:

Using Power BI Desktop, how can I present Time Duration in a matrix that converts it to decimal?

I have Begin Date and End Date in my data file (Excel), then in PowerQuery I add a column where I simply subtract the Begin Date from End Date to create a new column "Import Time", change the result's data type to Duration and in PowerQuery, the column correctly shows the difference expressed in Day:Hour:Minute:Seconds. However, in a report, I need to show the average not of an entire column, but of groups of values in a matrix based on the entire table. In other words, I'm looking for a table that shows columns for Category Name, Avg. Duration and Max Duration, with rows showing the results for each unique Category.
The problem is that when I drag a table field in to the Visualizations Value area and change to Average, it expresses the result as a decimal, and I can't figure out how to show the date / time equivalent. I thought I might have to multiply by 3,600 since the result might be shown in milliseconds, but that didn't work. Any thoughts?
So I theorized that perhaps the issue wasn't one with Power BI, but perhaps with how Microsoft expresses date / time computations. I edited my Excel file that contains the source data and computed the "Import Time" by subtracting Begin Time from End Time. By default, it displays in date / time format of "hh:mm:ss.0000". I then asked Google and came across a simple explanation: to express a date / time in numeric format, you need to multiply the date / time by 24 (hours), 60 (minutes) and 60 (seconds) if that's how you wanted to express the result. I then created a Pivot Table summarizing the average of the Import Times and saw the same thing I did in my Power BI report, which is when it clicked it for me.
To solve the issue, I edited my Power Query step to compute the import time and included " * 24 * 60 * 60" in the formula. After updating the report, the results matched what I saw in Excel and I'm good. Hopefully this helps others to deal with this vexing issue.
You wrap your averaging measure in a FORMAT function to convert it to precisely the text format you want to show in your matrix. For example, suppose your raw output is
Group AvgDuration
------------------
A 0.0633
B 0.2733
C 0.0600
These numbers are in the unit of days, so you can convert to hours, minutes, or seconds like this e.g.:
FORMAT ( [AvgDuration] * 24, "0.00h" )
FORMAT ( [AvgDuration] * 24 * 60, "#,0m" )
FORMAT ( [AvgDuration] * 24,* 60 * 60, "#,0s" )
FORMAT ( [AvgDuration], "hh:mm:ss" )
(where [AvgDuration] is your measure you use to calculate the average)
Those last two should look like this:
Group AvgDuration
------------------
A 5,472s
B 23,616s
C 5,184s
and
Group AvgDuration
------------------
A 01:31:12
B 06:33:36
C 01:26:24

MS Access Custom Formatting: Currency in K

I am trying to create an appropriate Format table property of a specific MS Access table in order to achieve the display style described below. For example purposes, let the table name be example and the field that I am trying to format be dollars
When example!dollars.Value is 567.98, I wish to display $0.567K. I also wish to display 1,000.42 as $1.000K.
In another table storing larger values, I use the Format property string $#,##0,\K; ($#,##0,"K)"[Red];"| < $1K |"; --, which successfully displays the amount in K dollars; however, any values less than $1K cannot be displayed. This is not acceptable due to the scale of the values in the example table.
The most intuitive solution is to use the string $0,000\K and specify the thousands separator as . instead of ,. However, I do not know how to do this.
Any advice will be greatly appreciated!
This works for me:
Kamount = Format(Amount/1000, "$0.000K")
So divide by 1000, then format as needed.
Use the Format property string $0\.000\K

Oracle spool Number rounding

I am calculating sum of all sales order (by multiplying quantity and price of a sales order - assume one sale order has only one item and using the sum function) in SQL query and I am spooling the output to a CSV file by using spool C:\scripts\output.csv.
The numeric output I get is truncated/rounded e.g. the SQL output 122393446 is made available in CSV as 122400000.
I tried to google and search on stackoverflow, but I could not get any hints about what can be done to prevent this.
Any clues?
Thanks
I think it is a xls issue.
Save as xls.
format column -> number with 2 decimals for example.
Initially I thought it might have something to do with the width of the number format which normally is 10 (NUMWIDTH) in sqlplus, but your result numeric width is 9, so that can not be the problem. Please check your query if you use a numeric type that doesn't have the required precission, and thus makes inexact calculations.

Sort strings numbers, like integer numbers in JQGrid

I had a jqgrid with float numbers. I tried to get rid of the right side 0 and group the numbers, so those are now like (for example: "123,242"), and you know that the type of them are now String.
I want to sort theme like integer numbers in jqgrid.
what should I do?
for example a part of a column
after sort(asc) these strings are like
this:
1,959
1,965
1,989
10,235
100
100
...
Thanks in advance.
I believe you implemented the indexing and sorting according to jqGrid document. For example: http://www.trirand.net/forum/default.aspx?g=posts&t=254
I assume you retrieved data from database. If you’ve followed those already, moreover, you may need to CAST or CONVERT that particular database field from STRING or VARCHAR into INT or NUMERIC when you bind your SQL query.
jqGrid is powerful to do rest of things automatically.
You can zero-pad them (e.g. 00100 and 01959), sort them, and then remove the padding. Computer Programming 0101.

Resources